我的图片显示有些问题。下面是我的代码:html背景图片无法正常显示
.night-sky {
position: relative;
height: 100%;
margin: 0;
background-repeat: no-repeat;
background-attachment: fixed;
background: -webkit-linear-gradient(top, #020107 0%, #311B46 50%, #592C67 60%, #803E7E 75%, #CA759C 90%, #EC9D9D 95%, #C35E4D 100%);
background: linear-gradient(to bottom, #020107 0%, #311B46 50%, #592C67 60%, #803E7E 75%, #CA759C 90%, #EC9D9D 95%, #C35E4D 100%);
}
.night-sky:before {
height: 100%;
width: 100%;
content: ' ';
position: absolute;
top: 0;
/* http://bg.siteorigin.com/ */
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/424395/night-sky-texture.png");
opacity: .1;
}
body {
height: 100%;
margin: 0;
background: #000;
}
<body>
<div class="night-sky">
<p>qerqwer</p>
<p>hahahh</p>
</div>
</body>
这是怎么看起来像现在:
如果我不添加类的div class = "night-sky"
之间的一段,它什么也没有显示。但如果我只是在身体中添加background-image
,它会正确显示。我不知道什么是错的。
谢谢。
可能是因为你有个高度,宽度没有定义。所以除非有元素,否则夜晚有宽度/高度。因此没有bg可见。看到没有段落的样本小提琴。 https://jsfiddle.net/5a2xowwg/ – aVC
链接:-http://www.html.am/html-codes/image-codes/background-image-code.cfm –