Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

divide "content" area into two columns?

Tags:

html

css

layout

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:

  • header
  • left navigation
  • content
  • footer

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?

like image 940
Fittersman Avatar asked May 15 '12 04:05

Fittersman


People also ask

How do you split the Flex box into two columns?

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.

How do I split a row into two columns in HTML?

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.


2 Answers

first layout preview (online demo):

enter image description here

html:
<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%;
}   

Second layout preview (online demo):

enter image description here

html is quite similar to first layout, but we include one wrapper to #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

like image 145
Vladimir Starkov Avatar answered Nov 15 '22 19:11

Vladimir Starkov


Give one of the CSS grid systems a go. This site lists some:10 Really Outstanding and Useful CSS Grid Systems

like image 34
Paul Marrington Avatar answered Nov 15 '22 20:11

Paul Marrington