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

18,694

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%;
      }
Share:
18,694
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    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?