I'm looking at making the transition from HTML tables to pure CSS layouts. So far, the one thing that eludes me is how to layout a page properly.
I can do:
So like this:
________________________
| Header |
|_______________________|
| Left | Content |
| Nav | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
|______|________________|
| Footer |
|_______________________|
However, on some pages I want to be able to divide the "content" area into something like the following:
________________________
| Header |
|_______________________|
| Left | info | info |
| Nav | | |
| | | |
| | | |
| | | |
| |______|_________|
| | Other info |
| | |
| | |
| | |
| | |
|______|________________|
| Footer |
|_______________________|
Anyone know how something like this would be done? Or even a nice website that helps with this kind of thing?
Approach: To create a two-column layout, first we create a <div> element with property display: flex, it makes that a div flexbox and then add flex-direction: row, to make the layout column-wise. Then add the required div inside the above div with require width and they all will come as columns.
Defining columns in HTML More columns can be added by adding more divs with the same class. The following syntax is used to add columns in HTML. <div class="row"> tag is used to initialize the row where all the columns will be added. <div class="column" > tag is used to add the corresponding number of columns.
<div id="header">Header</div>
<div id="main-wrap">
<div id="sidebar">Left Nav</div>
<div id="content-wrap">Content</div>
</div>
<div id="footer">Footer</div>
css:
/* sizes */
#main-wrap > div { min-height: 450px; }
#header,
#footer {
min-height: 40px;
}
/* layout */
#main-wrap {
/* overflow to handle inner floating block */
overflow: hidden;
}
#sidebar {
float: left;
width: 30%;
}
#content-wrap {
float: right;
width: 70%;
}
#content-wrap
:
<div id="header">Header</div>
<div id="main-wrap">
<div id="sidebar">Left Nav</div>
<div id="content-wrap">
<div id="info-wrap">
<div class="info">small info </div>
<div class="info">small info</div>
</div>
Content
</div>
</div>
<div id="footer">Footer</div>
css is also similar, by the way we added some css
rules to target new div's:
/* sizes */
#main-wrap > div { min-height: 450px; }
#header,
#footer {
min-height: 40px;
}
.info { min-height: 80px; }
/* layout */
#main-wrap {
/* overflow to handle inner floating block */
overflow: hidden;
}
#sidebar {
float: left;
width: 30%;
}
#content-wrap {
float: right;
width: 70%;
}
#info-wrap {
/* overflow to handle inner floating block */
overflow: hidden;
}
.info {
width: 50%;
float: left;
}
update: improved styles
Give one of the CSS grid systems a go. This site lists some:10 Really Outstanding and Useful CSS Grid Systems
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With