首页 > 解决方案 > 为什么背景图像属性不起作用?

问题描述

我的index.html文件和img文件夹位于同一目录中,我想将背景图像 div放在.img1.

所以我正在做这样的事情:

索引.html

.img1 {
  background-image: url("img/bg-header.jpg");
  position: relative;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
}
<div class="img1">
  <div class="ptext">
    <div class="dark-overlay">
      <div class="home-inner text-center">
        <h2 class="display-4 text-center">PULSES</h2>
        <br>
        <p> HALUTZIM 26 TEL AVIV<br><br><a href="tel:+972-50-4410600">+4410600</a></p>
        <br>
        <br>
        <div class="arrow">
          <i class="fas fa-chevron-down"></i>
        </div>
      </div>
    </div>
  </div>

</div>

这应该设置 div 的背景图像,但它不起作用?

笔记:

正如我提到的index.html style.cssimg文件夹位于同一目录中,我在img文件夹中有图像。难道我做错了什么 ?

请帮忙谢谢

标签: htmlcss

解决方案


尝试使用标记将图像呈现为页面中的内嵌图像,以确认路径正常。如果路径没问题,检查 div 的宽度和高度,然后使用background-postion属性。

如果仍然无法正常工作,请发布您的 html 头。


推荐阅读