16:9 padding-bottom trick not working as expected in FireFox

Viewed 5372

I've been trying to implement the responsive 16:9 ratio trick for a content block and while getting the expected result in Chrome, other browsers such as FireFox and Edge display it completely differently and not as intended.

.streamContainer {
  position: absolute;
  width: 80%;
  height: calc(100% - 120px);
  display: flex;
  bottom: 0px;
  flex-direction: column;
  justify-content: center;
  box-sizing: border-box;
  transition: height 0.5s;
  background: blue;
}
.streamRatio {
  position: relative;
  width: 100%;
  padding: 56.25% 0 0 0;
  content: '';
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  display: block;
  background: red;
  height: 0;
}
.streamInner {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: green;
}
<div class="streamContainer">
  <div class="streamRatio">
    <div class="streamInner">
      Content Goes Here
    </div>
  </div>
</div>

The following images show the intended result on Chrome and the unintended result on FireFox:

Chrome Chrome - Imgur
FireFox FireFox - Imgur

The blocks of color are just there to help visualise the different boxes.

3 Answers

Inside display:flex, Firefox does not accept percentage padding.

I added

display:table;
padding-bottom:56.25%;

and it fixed the problem, although I'm not sure if it comes with another problems. I couldn't see any problem after when testing with IE Chrome Safari and Firefox. at least at recent versions.

Related