CSS - Set Div Width 100% and Resize Keeping Aspect Ratio

后端 未结 4 987
天命终不由人
天命终不由人 2021-01-24 05:03

I have a div with a background image that will overlay part of the header slideshow. I want the width of the div to always be 100% of the window size, even when the user re-size

4条回答
  •  温柔的废话
    2021-01-24 05:42

    This somewhat distorts the image, but it might be what you are looking for:

    #bg_img {
        background: url('http://rndimg.com/ImageStore/OilPaintingBlue/999x400_OilPaintingBlue_19aa91c1b6e142f288fe69eb2a160a2b.jpg') no-repeat;
    min-width:100%;
    min-height:100%;
    background-size:cover;
    }
    

提交回复
热议问题