我创建了一个 <div>
<body>
中的第一件事在页面顶部画一条顶线:
<body>
<div class="bordertop"></div>
.....
</body>
和风格:
body {
font-family: Helvetica, Arial, sans-serif;
-webkit-text-size-adjust: 100%;
margin:0;
}
.bordertop {
background-image: url(../images/top_border.png);
background-repeat: repeat-x;
}
然而,top_border image
除非我在 <div>
中写一些文字,否则不会出现但我不想。我该如何解决这个问题?
最佳答案
由于 div 是空的,因此没有内容可以将其“打开”,从而使 div 的高度为 0px。在 div 上设置明确的尺寸,您应该会看到背景图像。
.bordertop
{
background-image: url(../images/top_border.png);
background-repeat: repeat-x;
height: 100px;
width: 100%; /* may not be necessary */
}
关于css - 如果 <div> 为空,背景图像不会出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11963687/