Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Horizontally splitting a page in half

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

CSS

#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;
}

HTML

<div id="container">

<div id="top_div">top</div>    
<div id="bottom_div">bottom</div>

</div>
like image 978
rudyStock Avatar asked Jan 07 '13 18:01

rudyStock


People also ask

How do I split a page horizontally in CSS?

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%.

How do you split a HTML page into two parts horizontally?

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.


1 Answers

Try this:

body, html, #container {
  height: 100%;
}
like image 66
jamesplease Avatar answered Oct 16 '22 03:10

jamesplease