Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split screen into 4 rectangles with 50% height 50% width

I am having trouble splitting a screen into 4 divs with width and height of 50%. It's no problem to get the 50% width and float them around, but how can I get each of them to have a height of 50% of the screen?

like image 862
Sven Klouem Avatar asked Dec 29 '22 06:12

Sven Klouem


1 Answers

I presume you've used to set your width; well the same thing can be used for your height.

For example:

<html>
<head>
</head>
<body>

<div style="background-color:red; width:50%; height:50%; float:left">
</div>

<div style="background-color:blue; width:50%; height:50%; float:right">
</div>

<div style="background-color:green; width:50%; height:50%; float:left">
</div>

<div style="background-color:orange; width:50%; height:50%; float:right">
</div>

</body>
</html>

If you run this, you will have 4 equal parts in your screen, with top-left being red, top-right being blue, bottom-left being green, and bottom-right being orange.

Edit this works with the following styles:

html,body {
        padding:0;
        margin:0;
        height:100%;
        min-height:100%;
      }
like image 128
Vincent Couture Avatar answered Dec 30 '22 20:12

Vincent Couture