I'm able to make a square div
element. But the same styles applied to an img
tag create a collapsed element- not a square.
.square{
width:20%;
border: 3px solid red;
}
.square:after{
content: "";
display: block;
padding-bottom: 100%;
}
img:<br>
<img class='square'/>
<br>
div:<br>
<div class='square'></div>
It seems this is because img
tags are replaced elements and :before
and :after
only work with non-replaced elements. source
But I want the img
element to stay square even if the image source doesn't load. So how can I make a square empty img
?