CSS 使用 position:fixed 伪元素时,IE11 不显示背景图片
CSS background image doesn't show up on IE11 when on position:fixed pseudo-element
JSfiddle 演示问题:
https://jsfiddle.net/qjtbchpu/11/
<div id="container">
<article>
blah
</article>
<article>
blah
</article>
</div>
#container::before {
left: 0;
right: 0;
bottom: 0;
top: 0;
content: '';
background: url(https://imgur.com/qYUPJgv.jpg);
position: fixed;
}
article {
position: relative;
height: 500px;
background: rgba(255, 255, 255, .75);
margin: 4em;
padding: 2em;
border: 1px solid black
}
这在我尝试过的所有主要浏览器中都完美运行,除了 IE11,在 IE11 中只有当我使用 position:absolute 时照片才会出现,这并没有给我想要的效果。
任何已知的解决方案或解决方法?谢谢
IE11 根本不会在那里加载大图像,猜测在创建伪元素时,它们不在缓存中。您的代码适用于一些 simple/small 图片,但对于更大的图片(需要时间加载)您可以使用这个技巧:
#container::before {
left: 0;
right: 0;
bottom: 0;
top: 0;
content: url(https://imgur.com/qYUPJgv.jpg);
background: url(https://imgur.com/qYUPJgv.jpg);
background-size: cover;
text-indent: -9999px;
overflow: hidden;
position: fixed;
}
article {
position: relative;
height: 500px;
background: rgba(255, 255, 255, .75);
margin: 4em;
padding: 2em;
border: 1px solid black
}
<div id="container">
<article>
blah
</article>
<article>
blah
</article>
</div>
经过测试,它工作正常,在 JSFiddle 上也是如此。
强制浏览器加载图像的关键行是:
content: url(https://imgur.com/qYUPJgv.jpg);
JSfiddle 演示问题:
https://jsfiddle.net/qjtbchpu/11/
<div id="container">
<article>
blah
</article>
<article>
blah
</article>
</div>
#container::before {
left: 0;
right: 0;
bottom: 0;
top: 0;
content: '';
background: url(https://imgur.com/qYUPJgv.jpg);
position: fixed;
}
article {
position: relative;
height: 500px;
background: rgba(255, 255, 255, .75);
margin: 4em;
padding: 2em;
border: 1px solid black
}
这在我尝试过的所有主要浏览器中都完美运行,除了 IE11,在 IE11 中只有当我使用 position:absolute 时照片才会出现,这并没有给我想要的效果。
任何已知的解决方案或解决方法?谢谢
IE11 根本不会在那里加载大图像,猜测在创建伪元素时,它们不在缓存中。您的代码适用于一些 simple/small 图片,但对于更大的图片(需要时间加载)您可以使用这个技巧:
#container::before {
left: 0;
right: 0;
bottom: 0;
top: 0;
content: url(https://imgur.com/qYUPJgv.jpg);
background: url(https://imgur.com/qYUPJgv.jpg);
background-size: cover;
text-indent: -9999px;
overflow: hidden;
position: fixed;
}
article {
position: relative;
height: 500px;
background: rgba(255, 255, 255, .75);
margin: 4em;
padding: 2em;
border: 1px solid black
}
<div id="container">
<article>
blah
</article>
<article>
blah
</article>
</div>
经过测试,它工作正常,在 JSFiddle 上也是如此。
强制浏览器加载图像的关键行是:
content: url(https://imgur.com/qYUPJgv.jpg);