Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: how to use vw and vh to make div in 16/9 ratio? [duplicate]

Tags:

html

css

I have the following setup:

#container {
  width: 100vw;
  height: calc(100vw / 1.77);
  display: block;
  background-color: black;
}
<div id="container">
</div>

I want to maintain always 16/9 aspect ratio.

But it isn't working! What am I wrong ?

like image 486
stighy Avatar asked Sep 20 '25 10:09

stighy


1 Answers

#container {
  display: block;
  width: 100vw;
  max-width: 177.78vh;
  /* 16/9 = 1.778 */
  height: 56.25vw;
  /* height:width ratio = 9/16 = .5625  */
  max-height: 100vh;
  background-color: black;
}
<div id="container">
</div>
like image 171
StefanBob Avatar answered Sep 23 '25 01:09

StefanBob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!