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

后端 未结 4 1047
天命终不由人
天命终不由人 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条回答
  •  萌比男神i
    2021-01-24 05:44

    This is what I've used in the past to support back to IE8. Used in conjunction with a small js plugin here that supports the filters: http://louisremi.github.io/jquery.backgroundSize.js/demo/

    img {
    -webkit-background-size:cover;
    -moz-background-size:cover;
    background-size:cover;
    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='cover');
    -ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='cover')";}
    background-position:50% 0;
    }
    

提交回复
热议问题