Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS to fill screen 50% 50% vertically [duplicate]

Tags:

enter image description here

What's the proper CSS to achieve this for most browsers?

  • 2 Divs - 50% and 50% vertically fill the entire screen.
  • Each div has 50% and 50% horizontally to fill 1600px width.
<!-- TOP 50% --> <div class="top">    <div class="left">img</div>    <div class="right">txt</div> </div>  <!-- BOT 50% --> <div class="bot">    <div class="left">text</div>    <div class="right">img</div> </div> 
like image 318
asdf Avatar asked May 30 '14 14:05

asdf


People also ask

How do you make a div cover a remaining height?

For anything inside the content div, setting top: 0; will put it right underneath the header. Sometimes the content will be a real table, with its height set to 100%.

What does 100% do in CSS?

It seems like this should be one of the easiest things to understand in CSS. If you want a block-level element to fill any remaining space inside of its parent, then it's simple — just add width: 100% in your CSS declaration for that element, and your problem is solved.


1 Answers

Goal:

You want a 2 x 2 grid of boxes. Each box is to be 50% of the window in height and width. This is actually much easier than you'd think. You don't need .left or .right, you don't need .top .bot. All you need is a single class called .row.

EDIT: You mentioned in comments that you want the width fixed at 1600px; We just need to add width to body.

Code

HTML:

<!-- TOP 50% --> <div class="row">    <div>img</div>    <div>txt</div> </div>  <!-- BOT 50% --> <div class="row">    <div>text</div>    <div>img</div> </div> 

CSS:

html,body {     padding:0;     margin:0;     height:100%; }  body {     width:1600px; }  .row {     width:100%;     height:50%; } .row div {     width:50%;     height:100%;     float:left; } 

Screenshot

This is from the example below, but I've added colors to make it easier to see.

Edit: The Fiddle has changed to include width. My screenshot is before the width, to demonstrate. It'll look a lot wider, because of the fixed width.

enter image description here

Working Example:

jsFiddle

like image 72
Andy Mercer Avatar answered Sep 20 '22 11:09

Andy Mercer