所以我想通过一个单独的CSS文件调用背景图像。 HTML文件和CSS文件位于同一级别,但背景图像的级别较低。为什么我的背景图片不会显示使用CSS?
例子:
的index.html
stylesheet.css中
资源>资产>背景图像
这里是我的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;
}
太感谢你了。我以为我曾尝试过,但显然不是。它工作完美。所以我的问题是,你什么时候使用“../” – smithky3
../是上面的一级。如果css位于自己的文件夹中,情况就会如此。检查我添加的CSS技巧链接,这完全解释了它。 –