CSS Web Layout
Web Layout
There are many ways to lay out a web page, which are generally divided into the following parts:Header area, menu navigation area, content area, and footer area.。

Header Area
The header area is located at the top of the entire web page and is generally used to set the page title or the website logo:
CSS3 Examples
.header
{
background-color:
#F1F1F1
;
text-align:
center
;
padding:
20
px
;
}
Try it »
Menu Navigation Area
The menu navigation bar contains a number of links that guide users to other pages:
CSS3 Examples
/*
Navigation bar
*/
.topnav
{
overflow:
hidden
;
background-color:
#333
;
}
/*
Navigation Link
*/
.topnav
a
{
float:
left
;
display:
block
;
color:
#f2f2f2
;
text-align:
center
;
padding:
14
px
16
px
;
text-decoration:
none
;
}
/*
Link - Change Color
*/
.topnav
a
:hover
{
background-color:
#ddd
;
color:
black
;
}
Try it »
Content Area
The content area generally has three forms:
- 1 column: generally used for mobile devices
- 2 columns: generally used for tablet devices
- 3 columns: generally used for PC desktop devices

We will create a 3-column layout that will become a 1-column layout on small screens (responsive):
CSS3 Examples
/*
Create Three Equal Columns
*/
.column
{
float:
left
;
width:
33.33
%
;
}
/*
Clear Floats After Columns
*/
.row
:after
{
content:
""
;
display:
table
;
clear:
both
;
}
/*
Responsive Layout - Change to a Top-and-Bottom Layout When the Screen Is Less Than 600 px
*/
@media
screen
and
(max-width: 600
px
)
{
.column
{
width:
100
%
;
}
}
Try it »
Tip:To set two columns, you can set width to 50%. To create four columns, you can set it to 25%.
Tip:If you want to learn more about @media rules, you can refer to CSS3 Media Queries。
Tip: Now a more advanced way is to use CSS Flexbox to create column layouts, but Internet Explorer 10 and earlier versions do not support this method; IE6-10 can use the float method.
For more information about CSS Flexbox, you can refer to CSS3 Flexible Box (Flex Box)。
Unequal Columns
Unequal columns generally set the content area in the middle, which is also the largest and most important, while the left and right sides can be used for navigation and other related content. The combined width of these three columns is 100%.
CSS3 Examples
.column
{
float:
left
;
}
/*
Width of the Left and Right Sidebars
*/
.column
.side
{
width:
25
%
;
}
/*
Width of the Middle Column
*/
.column
.middle
{
width:
50
%
;
}
/*
Responsive Layout - Set a Top-and-Bottom Layout When the Width Is Less Than 600px
*/
@media
screen
and
(max-width: 600
px
)
{
.column
.side
,
.column
.middle
{
width:
100
%
;
}
}
Try it »
Bottom area
The footer area is at the very bottom of the web page and generally contains copyright information and contact details.
CSS3 Examples
.footer
{
background-color:
#F1F1F1
;
text-align:
center
;
padding:
10
px
;
}
Try it »
Responsive Web Layout
Through the above learning, let's create a responsive page whose layout adjusts according to the screen size:
CSS3 Examples
{
box-sizing:
border-box
;
}
body
{
font-family:
Arial
;
padding:
10
px
;
background:
#f1f1f1
;
}
/*
Header Title
*/
.header
{
padding:
30
px
;
text-align:
center
;
background:
white
;
}
.header
h1
{
font-size:
50
px
;
}
/*
Navigation bar
*/
.topnav
{
overflow:
hidden
;
background-color:
#333
;
}
/*
Navigation Bar Links
*/
.topnav
a
{
float:
left
;
display:
block
;
color:
#f2f2f2
;
text-align:
center
;
padding:
14
px
16
px
;
text-decoration:
none
;
}
/*
Link Color Changes
*/
.topnav
a
:hover
{
background-color:
#ddd
;
color:
black
;
}
/*
Create Two Columns
*/
/*
Left column
*/
.leftcolumn
{
float:
left
;
width:
75
%
;
}
/*
Right Sidebar
*/
.rightcolumn
{
float:
left
;
width:
25
%
;
background-color:
#f1f1f1
;
padding-left:
20
px
;
}
/*
Image Section
*/
.fakeimg
{
background-color:
#aaa
;
width:
100
%
;
padding:
20
px
;
}
/*
Article Card Effect
*/
.card
{
background-color:
white
;
padding:
20
px
;
margin-top:
20
px
;
}
/*
Clear Floats After Columns
*/
.row
:after
{
content:
""
;
display:
table
;
clear:
both
;
}
/*
Footer
*/
.footer
{
padding:
20
px
;
text-align:
center
;
background:
#ddd
;
margin-top:
20
px
;
}
/*
Responsive Layout - Change the Two-Column Layout to a Top-and-Bottom Layout When the Screen Size Is Less Than 800px
*/
@media
screen
and
(max-width: 800
px
)
{
.leftcolumn
,
.rightcolumn
{
width:
100
%
;
padding:
0
;
}
}
/*
Responsive Layout - Change the Navigation Layout to a Top-and-Bottom Layout When the Screen Size Is Less Than 400px
*/
@media
screen
and
(max-width: 400
px
)
{
.topnav
a
{
float:
none
;
width:
100
%
;
}
}
Try it »