我有一个标题,我试图通过图像文件向其应用背景纹理。 html、css 和图像文件都在同一个目录中。这是 html:
<body>
<div id=header>
<div id=picture>
<img=src=picture.jpeg alt="Profile" align="right" width="180" height="180"/>
</div>
<div id=caption>
<h1>BannerText</h1>
</div>
</div>
</body>
这是外部样式表代码:
#header
{
background= url('texture.png');
width:98%;
}
纹理图像不出现。如果我将它与原始body标签的背景属性一起使用,即
<body background="texture.png">
确实有效。这告诉我这不是 url 的问题,所有三个文件都在同一个文件夹中,因此 html 和 css 文件中的相对路径是相同的。为什么纹理图像不显示为页眉 div 的背景?
最佳答案
是 background: url('texture.png');
, 不是 background= url('texture.png');
.
还有
<img src="picture.jpeg" alt="Profile" align="right" width="180" height="180"/>
不是
<img=src=picture.jpeg alt="Profile" align="right" width="180" height="180"/>
最好将属性值用引号引起来。对 - <div id="picture">
,
不好 - <div id=picture>
关于html - 为什么 background-image 不显示在 css 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17415429/