How can I make the height and width of a container equal to the height and width of it’s background image?
THANKS!
hey, i think you might want to just use width or height on the image but not both of them together as it can distort your image.
however, if you still want to use a specific height then try using the object-fit property on the img element.
.img{
height: 400px; //set the height
width: 100%;
object-fit: cover;
}
if you want more information on styling images read this article from mdn.
https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Images_media_form_elements
I think the spelling of width is wrong
Hahaha Thanks a lot for letting me know
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.