html - 将背景图像放在 div 标签中

标签 html css image background

我试图在跨越 h1、h2 和水平导航栏的 div 标记中显示图像作为背景。我的图像路径是正确的——我测试它作为 h1、h2 等的背景。但是,当它放在我的 div 标签中时它不会显示。此外,如果我尝试只使用一种简单的颜色作为我的 div 标签的背景,那也不起作用。

CSS:

#main{
    background-image:url("images/wall.png");
    position:relative;
    width:100%;
    height:100%;
}

HTML:

<div id="main">
    <h1>Brian Buch</h1>
    <h2>Pianist</h2>
<div id="nav">
    <ul>
        <li>recordings</li>
        <li>calendar</li>
        <li>bookings</li>
    </ul>
</div>
</div>

最佳答案

您已将图像放入“images”文件夹,因此您可能已将 css 放入“css”文件夹。

如果是这样,试试这个:

background-image:url("../images/wall.png");

css 从它自己的相对路径调用背景图像...而不是使用 css 的页面的相对路径。

这将强制页面在/images 目录中查找,而不是/css/images 目录。

关于html - 将背景图像放在 div 标签中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26820362/

相关文章:

html - CSS 显示 : inline-block drops to next line

css - 如何获取默认的 wordpress 管理样式

html - 不同浏览器的 CSS3 渲染不同

css - Angular 8中页面加载后触发动画,ExpressionChangedAfterItHasBeenCheckedError

php - 可扩展的异步图像大小调整

image - 图像的显性 "color"

python - 如果在 HTML 页面中找不到文本,如何在 python 中打印空值?

html - 如何将 Html 转换为 Prolog

html - 文本行转到新行,而不是换行,即使使用自动换行 :break-word

c# - 从 varbinary case sql server c# 中读取图像