I would like to create centered html page with three separated columns (with different colors). I can't find solution for my #container1 in css. The red color is spreading from left side(out of the centered page). Here it is: http://imgur.com/D3ZAV can someone please help me? thanks
<body>
<div id="cela">
<div id="header">
<p>hlavicka</p>
</div>
<div id="container3">
<div id="container2">
<div id="container1">
<div id="lavy"><p>Etiam ante est</p></div>
<div id="stredny"><p>Mauris orci erat</p></div>
<div id="pravy"><p>Quisque tincidunt congue orci, </p></div>
</div>
</div>
</div>
<div id="footer">
<p>footer</p>
</div>
</div>
</body>
CSS file
#cela {
width: 80%;
margin-left: auto;
margin-right: auto;
border: 1px #110000 solid;
}
#header
{
padding:20px;
background:#008000;
}
#footer
{
clear: both;
padding:20px;
background:#008000;
}
#container3 {
float:left;
width:100%;
background:green;
}
#container2 {
float:left;
width:100%;
background:yellow;
position:relative;
right:30%;
}
#container1 {
float:left;
width:100%;
background:red;
position:relative;
right:40%;
}
#container0 {
float:left;
width:100%;
background:white;
position:relative;
right:0%;
}
#lavy
{开发者_C百科
float:left;
width:30%;
position:relative;
left:70%;
}
#stredny
{
float:left;
width:40%;
position:relative;
left:70%;
}
#pravy
{
float:left;
width:30%;
position:relative;
left:70%;
}
(sorry for bad formatting, i can't figure out why it is so shitty )
You really need to reconsider your approach to this problem.
I'd suggest: 3 floated divs wrapped in a container.
<div id="container">
<div id="column1">Lorem ipsum</div>
<div id="column2">Dolor sit amet</div>
<div id="column3">Mauris orci</div>
</div>
And as for your CSS, there are a few significant things you can build on:
#container {
overflow: hidden; //this will clear the floated columns
width: 960px;
}
#column1 {
float: left;
width: 320px;
background: #f00;
}
#column2 {
float: left;
width: 320px;
background: #0f0;
}
#column3 {
float: left;
width: 320px;
background: #00f;
}
Essentially:
- Wrap the floats and clear them using
overflow: hidden;
- The total width of the floats is equal to the width of the container
精彩评论