Pergunta

How can I align 4 divs, in css, inside a container like in this image: http://postimg.org/image/w0k7wgdfb/ Here's my html, I guess I need another container for DIV#2 and DIV#3.

<div id="container">
   <div id="header"> DIV 1 </div>
    <div id="wraper"> <!-- WRAPER -->
      <div id="sidebar"> DIV 2 </div>
      <div id="content"> DIV 3 </div>
    </div> <!-- WRAPER -->
   <div id="footer"> DIV4 </div>
</div>

Thank you for your help!

Foi útil?

Solução

Solution 1 - Floats

After centre aligning the content, you could use a simple float trick for the two middle divs:

CSS

html, body {
    height: 100%;
    width:100%;
    margin: 0;
    padding: 20px;
    box-sizing:border-box;
}
#container {
    text-align:center;
    width:500px;
    margin: 0 auto;
    height:100%;
    background:black;
    padding:20px;
    box-sizing:border-box;
}
#header {
    background:green;
    height:20%;
}
#wraper {
    height:60%;
    overflow:hidden;
}
#sidebar {
    width:20%;
    float:left;
    height:100%;
    background:red;
}
#content {
    overflow:hidden;
    background:blue;
    height:100%;
}
#footer {
    background:orange;
    height:20%;
}

Solution 2 - Display:Table

After centre aligning the content, you could apply a table layout to the middle divs

CSS

html, body {
    height: 100%;
    width:100%;
    margin: 0;
    padding: 20px;
    box-sizing:border-box;
}
#container {
    text-align:center;
    width:500px;
    margin: 0 auto;
    height:100%;
    background:black;
    padding:20px;
    box-sizing:border-box;
}
#header {
    background:green;
    height:20%;
}
#wraper {
    height:60%;
    display:table;
    width:100%;
}
#sidebar {
    width:20%;
    display:table-cell;
    background:red;
}
#content {
    display:table-cell;
    background:blue;
}
#footer {
    background:orange;
    height:20%;
}

Outras dicas

Here there is a working fiddle.
HTML

CSS

 #one{
        width: 400px;
        background: black;
        margin: 0 auto;
        height: 600px;
    }
    #two{
        height: 100px;
        width: 400px;
        background: lime;
    }
    #three{
        height: 400px;
        width: 100px;
        background: yellow;
        float: left;
    }
    #four{
        height: 400px;
        width: 300px;
        background: blue;
        float: left;
    }
    #five{
        height: 100px;
        clear: both;
        width: 400px;
        background: silver;
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top