html - 为什么 background-image 不显示在 css 中?

标签 html css image background

我有一个标题,我试图通过图像文件向其应用背景纹理。 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/

相关文章:

python - 显示从 zip 存档 python 读取的图像

javascript - 从下拉列表中选择选项

html - 如何将空字符输入到网络表单中?

html - 在正确的 HTML 中,&lt;input&gt; 必须在 <form> 中吗?

jquery - 输出用户在文本区域中输入的特定值

css - 如何在 CSS 中使导航栏居中

css - 更改 Bootstrap 分页的背景颜色

php - 将图像从 iOS 应用程序上传到 php --- 不太正确 --- 我错过了什么?

html - 为什么 'filter' 在 Windows 8 应用程序中不是已知的 CSS3 属性名称?

c# - 使用黑白图像进行 Blob 跟踪