I am trying to make a responsive square in CSS, I wrote the following HTML for the same.
.square-container {
position: relative;
height: 0;
width: 50%;
padding-bottom: 50%;
}
.content {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
object-fit: cover;
}
<div class="square-container">
<img class="content" src="https://static.toiimg.com/photo/48553824/.jpg">
</div>
This code is working perfectly. But I have a doubt, how is the height of child element that is img in this case is effected by padding-bottom
of parent element.