Three Column Website Layout in CSS
Now let's make a three-column layout. Here's an example of what we should get:
First, let's write the structure of the site:
<div id="wrapper">
<div id="header">
header
</div>
<div id="container">
<div id="left">
left sidebar
</div>
<div id="content">
content
</div>
<div id="right">
right sidebar
</div>
</div>
<div id="footer">
footer
</div>
</div>
Let's set the width of the wrapper and center it:
#wrapper {
width: 1100px;
margin: 30px auto;
border: 1px solid black;
}
Let's put the container blocks in a row:
#container {
display: flex;
}
Now let's assign the widths of the blocks so that in total they give the width of the wrapper:
#content {
width: 700px;
}
#left {
width: 200px;
}
#right {
width: 200px;
}
Let's now add margin
ы, pinching their width from the content:
#content {
width: 660px;
}
#left {
width: 200px;
margin-right: 20px;
}
#right {
width: 200px;
margin-left: 20px;
}
Let's add the rest of the styles:
#content {
width: 660px;
height: 700px;
padding: 20px;
border: 1px solid black;
}
#left {
width: 200px;
margin-right: 20px;
padding: 20px;
border: 1px solid black;
}
#right {
width: 200px;
margin-left: 20px;
padding: 20px;
border: 1px solid black;
}
Let's write the final code:
<div id="wrapper">
<div id="header">
header
</div>
<div id="container">
<div id="left">
left sidebar
</div>
<div id="content">
content
</div>
<div id="right">
right sidebar
</div>
</div>
<div id="footer">
footer
</div>
</div>
* {
box-sizing: border-box;
}
#wrapper {
width: 1100px;
margin: 30px auto;
border: 1px solid black;
}
#header {
height: 200px;
padding: 20px;
border: 1px solid black;
}
#container {
display: flex;
}
#content {
width: 660px;
height: 700px;
padding: 20px;
border: 1px solid black;
}
#left {
width: 200px;
margin-right: 20px;
padding: 20px;
border: 1px solid black;
}
#right {
width: 200px;
margin-left: 20px;
padding: 20px;
border: 1px solid black;
}
#footer {
height: 200px;
padding: 20px;
border: 1px solid black;
}