Use height:100% inside a div with aspect-ratio set - bug in certain browsers?

95 Views Asked by At

Note: This question about a new feature in CSS: aspect-ratio. Most of the questions on this site with similar keywords are about very different techniques.

Ok so there's a div with the following properties set: width, aspect-ratio, & max-height. Inside of it is another div with height: 100%. Works great in desktop chrome & desktop firefox. Does not work in desktop safari, mobile safari, or mobile chrome.

Here's how it should look (or at least does look in desktop Chrome):
enter image description here

Here's how it looks in mobile Chrome:
enter image description here

Here's the code (jsbin here):

    div {
      box-sizing: border-box;
    }
    .con3 {
      border: 4px solid black;
      width: 200px;
      height: 200px;
    }
    .con2 {
      border: 4px solid violet;
      width: 100%;
      aspect-ratio: 9 / 16;
      max-height: 100%;
    }
    .con1 {
      border: 4px solid skyblue;
      height: 100%;
      aspect-ratio: 9 / 16;
      max-width: 100%;
    }
<body>
  <div class="con3">
    <div class="con2">
      <div class="con1">
        hi
      </div>
    </div>
  </div>
</body>

Curious about:

  1. Anyone aware of what's happening here?
  2. Is there an existing bug filed about this?
  3. Have any work-arounds that keep the use of aspect-ratio on the parent?
1

There are 1 best solutions below

0
tybro0103 On

A workaround I've found is to use position:absolute on the child.

.con2 {
  position: relative;
}
.con1 {
  position: absolute;
}