Loading course content...
Loading course content...
Code Playground is only enabled on larger screen sizes.
Besides the flexbox and grid, there is also a legacy method called the grid view.
This method divides the webpage into 12 columns, each taking 1/12 of the entire viewport width. You can then decide how many columns an element should occupy.
.col-1 {
width: 8.33%;
}
.col-2 {
width: 16.66%;
}
.col-3 {
width: 25%;
}
.col-4 {
width: 33.33%;
}
.col-5 {
width: 41.66%;
}
.col-6 {
width: 50%;
}
.col-7 {
width: 58.33%;
}
.col-8 {
width: 66.66%;
}
.col-9 {
width: 75%;
}
.col-10 {
width: 83.33%;
}
.col-11 {
width: 91.66%;
}
.col-12 {
width: 100%;
}Create the same grid view for medium and large screens.
@media screen and (min-width: 640px) {
.col-md-1 {
width: 8.33%;
}
.col-md-2 {
width: 16.66%;
}
.col-md-3 {
width: 25%;
}
.col-md-4 {
width: 33.33%;
}
.col-md-5 {
width: 41.66%;
}
.col-md-6 {
width: 50%;
}
.col-md-7 {
width: 58.33%;
}
.col-md-8 {
width: 66.66%;
}
.col-md-9 {
width: 75%;
}
.col-md-10 {
width: 83.33%;
}
.col-md-11 {
width: 91.66%;
}
.col-md-12 {
width: 100%;
}
}
@media screen and (min-width: 1024px) {
.col-lg-1 {
width: 8.33%;
}
.col-lg-2 {
width: 16.66%;
}
.col-lg-3 {
width: 25%;
}
.col-lg-4 {
width: 33.33%;
}
.col-lg-5 {
width: 41.66%;
}
.col-lg-6 {
width: 50%;
}
.col-lg-7 {
width: 58.33%;
}
.col-lg-8 {
width: 66.66%;
}
.col-lg-9 {
width: 75%;
}
.col-lg-10 {
width: 83.33%;
}
.col-lg-11 {
width: 91.66%;
}
.col-lg-12 {
width: 100%;
}
}Then you can apply this layout to your HTML document like this
<div class="container">
<div class="nav col-12 col-md-12">Navbar</div>
<div class="side-primary col-12 col-md-4 col-lg-3">Primary sidebar</div>
<div class="content col-12 col-md-8 col-lg-6">
Main Content
<p>Lorem ipsum dolor sit. . .</p>
</div>
<div class="side-secondary col-12 col-md-12 col-lg-3">Secondary sidebar</div>
<div class="footer col-12">Footer</div>
</div>Take the primary sidebar as an example.
On small screens, the element will take all 12 columns.
<div class="container">
<div class="nav col-12 col-md-12">Navbar</div>
<div class="side-primary col-12 col-md-4 col-lg-3">Primary sidebar</div>
<div class="content col-12 col-md-8 col-lg-6">
Main Content
<p>Lorem ipsum dolor sit. . .</p>
</div>
<div class="side-secondary col-12 col-md-12 col-lg-3">Secondary sidebar</div>
<div class="footer col-12">Footer</div>
</div>On medium screens, the sidebar takes four columns.
<div class="container">
<div class="nav col-12 col-md-12">Navbar</div>
<div class="side-primary col-12 col-md-4 col-lg-3">Primary sidebar</div>
<div class="content col-12 col-md-8 col-lg-6">
Main Content
<p>Lorem ipsum dolor sit. . .</p>
</div>
<div class="side-secondary col-12 col-md-12 col-lg-3">Secondary sidebar</div>
<div class="footer col-12">Footer</div>
</div>And on large screens, the sidebar takes only three columns.
<div class="container">
<div class="nav col-12 col-md-12">Navbar</div>
<div class="side-primary col-12 col-md-4 col-lg-3">Primary sidebar</div>
<div class="content col-12 col-md-8 col-lg-6">
Main Content
<p>Lorem ipsum dolor sit. . .</p>
</div>
<div class="side-secondary col-12 col-md-12 col-lg-3">Secondary sidebar</div>
<div class="footer col-12">Footer</div>
</div><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="/styles.css"> </head> <body> <div class="container"> <div class="nav">Navbar</div> <div class="side-primary">Primary sidebar</div> <div class="content"> Main Content <p>. . .</p> </div> <div class="side-secondary">Secondary sidebar</div> <div class="footer">Footer</div> </div> </body> </html>