alazizie alazizie - 3 months ago 8
CSS Question

How to make a div resizable like in (background-size:100%)?

I want a div height/width to be dynamically resized together when window width is resizing just like in (background-size:100%), and I prefer using only CSS "if possible".

Thank you in advance :)

Answer

You can set width:100%; and height:auto; Also try to do the same for images inside that div

img{
     width:100%
     height:auto;
}

That will make the img responsive and will not overflow the parent div

Also you can use this

img {
    max-width: 100%;
    height: auto;
}

The image will scale down if it has to, but never scale up to be larger than its original size

Comments