Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CSS Aspect Ratio in flexbox container

I’m trying to make a div that fills all available height of its parent, while maintaining a 16/9 aspect ratio. However, it’s filling the width and thus not keeping the aspect ratio I’ve set. Any advice on how to fix this?

<div class="outer">
  <div class="problem"></div>
  <div class="inner"></div>
</div>
.outer {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.problem {
  height: 200px;
}
.inner {
  aspect-ratio: 16/9;
  background-color: blue;
}

html,body {
  margin: 0;
  font-family: sans-serif;
}

JSFiddle: https://jsfiddle.net/cqhtb8sw/

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s due to flexbox, you can add this in your inner styles:

  height:100%;
  width: min-content;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading