添加到 CSS 中的 div 的背景图片未显示在本地主机中

background image added to a div in CSS is not showing up in localhost

所以我使用 CSS 向 div 添加了背景图片。

.aboutUs {
  background-repeat: no-repeat;
  position: relative;
  background-image: url(public/images/team.png);
  text-align: center;
  background-size: cover;
  height: 310px;
  margin: 10px;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  padding-top: 20px;
  border-bottom-left-radius: 50%;
  border-bottom-right-radius: 50%;
}

但是当我在本地主机中打开它时,所有图像(在 HTML 中)都显示了,但是 div background is not showing up.

在我的控制台中它给了我 this error

非常感谢大家的帮助! #happyCoding! :D

也许试试这个?

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

尝试为您的 div 添加背景颜色,看看您的风格是否有效。

从报错可以看出你这里的图片相对路径不对。

background-image: url(public/images/team.png);

检查您的文件夹结构并相应地设置您的 url。

试试这个风格。

    background: url('../../../images/animated-strawberry-image-0052.gif') center center no-repeat no-repeat;        
    position: absolute;
    width: 100%;
    height: 100%;

检查你的照片 url 是否正确

检查你的目录结构

folder
   \public
    \image
       team.png
   \sub-folder
    style.css

background-image: url(../public/team.png);


folder
   \public
    \image
       ..team.png
   ..style.css
   \sub-folder
    
background-image: url(public/image.png);

folder
   \public
    \image
       ..team.png

   \sub-folder
    \another-folder
       ..style.css  
background-image: url(../../public/image.png);