所以我试图通过一个单独的 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/