0

I have a div that have a 50% of screen's width. inside of it I want to make four squares:

<div style="width:50%">
  <div style="width:25%"></div>
  <div style="width:25%"></div>
  <div style="width:25%"></div>
  <div style="width:25%"></div>
</div>

but I don't know how to calculate of height of them. I don't want to use js.

S.M_Emamian
  • 17,005
  • 37
  • 135
  • 254

1 Answers1

0

Instead of percentages, have your inner divs use viewport-percentage lengths:

<div style="width:50%;background-color:red;">
    <div style="width:25vw;height:25vw;background-color:blue;"></div>
    <div style="width:25vw;height:25vw;background-color:green;"></div>
    <div style="width:25vw;height:25vw;background-color:blue;"></div>
    <div style="width:25vw;height:25vw;background-color:green;"></div>
</div>

(Background colors for the purpose of the demo.)

Abion47
  • 22,211
  • 4
  • 65
  • 88