26

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>
asdf
  • 295
  • 1
  • 3
  • 7

3 Answers3

20

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

Kelderic
  • 6,502
  • 8
  • 46
  • 85
2

There are a few ways to achieve this. I tend to favour this one:

http://jsfiddle.net/YyBW7/

.top, .bot {
    height: 50%;
    border: 1px solid black;
    box-sizing: border-box;
}

.left, .right {
    display: inline-block;
    width: 50%;
    height: 100%;
    margin-right: -4px;
    border: 1px solid red;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    padding: 0;
    margin: 0;
}
Samih
  • 1,078
  • 9
  • 15
0

I think there were some things missing from Samih's answer. Probably float See if this gets you better results: jsFiddle

Narong
  • 476
  • 1
  • 3
  • 15