This is the strangest thing, I have used this method many times before but it seems to be breaking for me now.
Here is a duplicate question that provides this method as an answer:
Maintain the aspect ratio of a div with CSS
But for some unknown reason it's breaking for me in Firefox and Chrome. From what I can gather it's calculating the padding according to the parent of the element I'm applying the style to...
In this case it's not looking at .test
but instead is looking at .parent
to calculate the padding:
.parent {
width: 200px;
}
.test {
width: 50px;
background: red;
padding-top: 100%;
}
<div class='parent'>
<div class='test'></div>
</div>
padding-top: 25%;
– Eldwun.test {width: 50px;}
to.test {width: 100%}
? What were you trying to achieve with the 50px? – Eldwun