Responsive Website:: Example
Responsive Website:: Example
body {
background-color: lightgreen;
Example :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
*{
box-sizing: border-box;
.topnav {
overflow: hidden;
background-color: #333;
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
text-decoration: none;
.topnav a:hover {
background-color: #ddd;
color: black;
/* On screens that are 600px wide or less, make the menu links stack on top of each other instead of next to each other */
.topnav a {
float: none;
width: 100%;
</style>
</head>
<body>
<p>Resize the browser window to see the effect: When the screen is less than 600px, the navigation menu will be displayed vertically instead of
horizontally.</p>
<div class="topnav">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>
</body>
</html>
Units :
Absolute Lengths
The absolute length units are fixed and a length expressed in any of these will appear as exactly that size.
Absolute length units are not recommended for use on screen, because screen sizes vary so much. However, they can be used if the output
medium is known, such as for print layout.
Unit Description
cm centimeters
mm millimeters
* Pixels (px) are relative to the viewing device. For low-dpi devices, 1px is one device pixel (dot) of the display. For printers and high resolution
screens 1px implies multiple device pixels.
Relative Lengths
Relative length units specify a length relative to another length property. Relative length units scale better between different rendering
medium.
Unit Description
em Relative to the font-size of the element (2em means 2 times the size of the current font)
Tip: The em and rem units are practical in creating perfectly scalable layout!
* Viewport = the browser window size. If the viewport is 50cm wide, 1vw = 0.5cm.
Animation :
@keyframes mymove {
from {background-color: red;}
to {background-color: blue;}
}
Or devide animation duration into frames , hence instead off from or to code with animation duration percentage percentage .
Dropdown menu :
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
li {
float: left;
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
text-decoration: none;
background-color: red;
li.dropdown {
display: inline-block;
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
z-index: 1;
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
</style>
</head>
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li class="dropdown">
<div class="dropdown-content">
</div>
</li>
</ul>
</body>
</html>
Slider :
<!DOCTYPE html>
<html>
<head>
<style>
* {box-sizing: border-box}
/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -22px;
color: white;
font-weight: bold;
font-size: 18px;
user-select: none;
.next {
right: 0;
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
.active, .dot:hover {
background-color: #717171;
/* Fading animation */
.fade {
animation-name: fade;
animation-duration: 1.5s;
@keyframes fade {
to {opacity: 1}
</style>
</head>
<body>
<div class="slideshow-container">
</div>
</div>
</div>
</div>
<br>
<div style="text-align:center">
</div>
<script>
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
function currentSlide(n) {
showSlides(slideIndex = n);
function showSlides(n) {
let i;
slides[i].style.display = "none";
slides[slideIndex-1].style.display = "block";
</script>
</body>
</html>
let slideIndex = 0;
showSlides();
function showSlides() {
let i;
let slides = document.getElementsByClassName("mySlides");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {slideIndex = 1}
slides[slideIndex-1].style.display = "block";
setTimeout(showSlides, 2000); // Change image every 2 seconds
}
<!DOCTYPE html>
<html>
<style>
body {
font-family: Arial;
margin: 0;
*{
box-sizing: border-box;
img {
vertical-align: middle;
}
/* Position the image container (needed to position the left and right arrows) */
.container {
position: relative;
.mySlides {
display: none;
.cursor {
cursor: pointer;
.prev,
.next {
cursor: pointer;
position: absolute;
top: 40%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
user-select: none;
-webkit-user-select: none;
.next {
right: 0;
.prev:hover,
.next:hover {
color: #f2f2f2;
font-size: 12px;
position: absolute;
top: 0;
.caption-container {
text-align: center;
background-color: #222;
color: white;
.row:after {
content: "";
display: table;
clear: both;
.column {
float: left;
width: 16.66%;
.demo {
opacity: 0.6;
.active,
.demo:hover {
opacity: 1;
</style>
<body>
<div class="container">
<div class="mySlides">
</div>
<div class="mySlides">
</div>
<div class="mySlides">
</div>
<div class="mySlides">
</div>
<div class="mySlides">
</div>
<div class="mySlides">
</div>
<div class="caption-container">
<p id="caption"></p>
</div>
<div class="row">
<div class="column">
</div>
<div class="column">
</div>
<div class="column">
</div>
<div class="column">
</div>
<div class="column">
</div>
<div class="column">
</div>
</div>
</div>
<script>
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
function currentSlide(n) {
showSlides(slideIndex = n);
function showSlides(n) {
let i;
slides[i].style.display = "none";
slides[slideIndex-1].style.display = "block";
captionText.innerHTML = dots[slideIndex-1].alt;
</script>
</body>
</html>
Website Layout :
<!DOCTYPE html>
<html>
<head>
<style>
*{
box-sizing: border-box;
body {
font-family: Arial;
padding: 10px;
background: #f1f1f1;
/* Header/Blog Title */
.header {
padding: 30px;
text-align: center;
background: white;
.header h1 {
font-size: 50px;
.topnav {
overflow: hidden;
background-color: #333;
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
text-decoration: none;
}
/* Change color on hover */
.topnav a:hover {
background-color: #ddd;
color: black;
/* Left column */
.leftcolumn {
float: left;
width: 75%;
/* Right column */
.rightcolumn {
float: left;
width: 25%;
background-color: #f1f1f1;
padding-left: 20px;
/* Fake image */
.fakeimg {
background-color: #aaa;
width: 100%;
padding: 20px;
.card {
background-color: white;
padding: 20px;
margin-top: 20px;
.row::after {
content: "";
display: table;
clear: both;
/* Footer */
.footer {
padding: 20px;
text-align: center;
background: #ddd;
margin-top: 20px;
/* Responsive layout - when the screen is less than 800px wide, make the two columns stack on top of each other instead of next to each other */
.leftcolumn, .rightcolumn {
width: 100%;
padding: 0;
/* Responsive layout - when the screen is less than 400px wide, make the navigation links stack on top of each other instead of next to each other */
.topnav a {
float: none;
width: 100%;
</style>
</head>
<body>
<div class="header">
<h1>My Website</h1>
</div>
<div class="topnav">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>
<div class="row">
<div class="leftcolumn">
<div class="card">
<h2>TITLE HEADING</h2>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
</div>
<div class="card">
<h2>TITLE HEADING</h2>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
</div>
</div>
<div class="rightcolumn">
<div class="card">
<h2>About Me</h2>
</div>
<div class="card">
<h3>Popular Post</h3>
<div class="fakeimg"><p>Image</p></div>
<div class="fakeimg"><p>Image</p></div>
<div class="fakeimg"><p>Image</p></div>
</div>
<div class="card">
<h3>Follow Me</h3>
<p>Some text..</p>
</div>
</div>
</div>
<div class="footer">
<h2>Footer</h2>
</div>
</body>
</html>