html - 为什么我的背景图像不会使用 CSS 显示?

标签 html css background-image

所以我试图通过一个单独的 CSS 文件调用背景图像。 HTML文件和CSS文件在同一层,但是背景图片低两层。

例子:

index.html

样式表.css

资源> Assets 背景图片

这是我的 html:

    <div class="second-background">
       <h2>Our</h2>
       <div class="purpose-heading"><h2>Purpose</h2></div>
       <p class="textstyle6">To provide unaccompanied runaway and homeless youth with a safe and nurturing environment where they can develop the needed skills to become active, healthy, successful members of our future world.</p>
       <div id="rectangle"><p class="textstyle2">7,085 MEALS SERVED. 511 DROP-IN SERVICES.<br/>245 STREET OUTREACH HOURS. 64 SHELTERED YOUTH.</p></div>
    </div>

这是我的 CSS:

.second-background {
background-image:url("../resources/assets/purpose.png");
}
#rectangle {
width: 1110px;
height: 105px;
background-color: #ffffff;
}

最佳答案

路径错误,将css中图片路径中的../去掉。如果结构像你说的那样。

在此处了解有关文件路径的更多信息:https://www.w3schools.com/html/html_filepaths.asp在这里:https://css-tricks.com/quick-reminder-about-file-paths/

关于html - 为什么我的背景图像不会使用 CSS 显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42776472/

相关文章:

html - 文本在带有输入字段的居中 div 中左对齐

css - 由 GitHub Pages 托管时无法看到背景图片

javascript - css 背景图像根本不显示

html - 响应式,两列布局 : Move one column in between other column

html - 关于 float div 父级的 Css

html - iframe 上的不透明度,前面有一个 div

html - 用背景图像填充 SVG 路径元素

javascript - 使用 JavaScript 确定/查找 HTML DIV 元素是否为空或未使用

html - 如何禁用封面页的缩放?

javascript - 相对位置偏移错误