I'm trying to have a page divided in half, horizontally. I want to accomplish it just by HTML/CSS and I'd prefer not to use JS. What am I doing wrong?
Thanks
#container {
min-height:100%;
}
#top_div {
height:50%;
width:100%;
background-color:#009900;
margin:auto;
text-align:center;
}
#bottom_div {
height:50%;
width:100%;
background-color:#990000;
margin:auto;
text-align:center;
color:#FFFFFF;
}
<div id="container">
<div id="top_div">top</div>
<div id="bottom_div">bottom</div>
</div>
For a better solution do the same with the top and bottom elements inside the container. Set them to position and all top, left,... properties to zero. For the top element set bottom to 50% and for the bottom element set top to 50%.
Using float and margin The left div is styled with width:50% and float:left – this creates the green colored div that horizontally covers half of the screen. The right div is then set to margin-left:50% – this immediately places it to the right of the left div.
Try this:
body, html, #container {
height: 100%;
}
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