我试图在我的导航栏上方创建一个全宽图像,但我什至无法在屏幕上显示该图像。这是我的简单 HTML:
<html>
<body>
<div class="wrapper" />
</body>
</html>
还有CSS:
.wrapper {
background-image: url(../assets/bridge.jpg);
background-repeat: no-repeat;
background-size: 100%;
width: 100%;
height: 100%;
}
我在浏览器中看到了 jpg 并且可以在我的资源中点击它,所以路径没有问题。屏幕还是一片空白,什么也没有显示。任何帮助都会很棒。
最佳答案
这是因为 height:100%
在功能上是无用的,因此您的 div 没有高度。
如果给 div 一个固定的高度,图像应该是 appear as expected .
或者,如果您希望背景图像应用于页面背景,您可以将其应用于 <html>
元素并避免整个包装,100% 崩溃。
html {
background-image: url(../assets/bridge.jpg);
background-repeat: no-repeat;
background-size: 100%;
}
关于HTML 背景图像未显示在屏幕上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16357064/