To achieve this particular effect, a somewhat unconventional method must be employed.
The solution involves adding an additional child element to the existing child element, which should be an image with an intrinsic ratio.
By using a square image, the resulting child element will also take on a square shape.
Although the image itself may not be visible, its presence is essential, so setting the opacity to 0 effectively hides it from view.
.father {
height: 300px;
width: 300px;
border: solid 1px black;
}
.child {
border: solid 1px blue;
background-color: lightblue;
height: 90%;
width: fit-content;
}
.child img {
height: 100%;
opacity: 0;
}
<div class="father">
<div class="child">
<img src="https://i.sstatic.net/04i18.png">
</div>
</div>