无法显示背景图片网址

时间:2015-11-02 22:25:36

标签: html css html5 css3

enter image description here

我无法展示图片而且我不知道是什么 从我试过以来,从css文件夹下到图像文件夹的子目录。

background: url('images/home1.jpg') top left no-repeat;

3 个答案:

答案 0 :(得分:1)

您以错误的顺序使用background速记。正确的顺序是:

  
      
  • 背景颜色
  •   
  • 背景图像
  •   
  • 背景重复
  •   
  • 背景附件
  •   
  • 背景位置
  •   
     

请参阅http://www.w3schools.com/css/css_background.asp

您案例中background的正确语法是:

background: #fff url("../images/home1.jpg") no-repeat top left;

答案 1 :(得分:1)

Amar Syla提供的答案是正确的,然而,它并没有真正指出问题的开始。首先,正如他/她提到的,background属性的简写语法是 CORRECT 。但是,如果未提及特定属性,则浏览器倾向于使用默认属性。这意味着,在这种情况下,缺少background-color属性是没有问题的。请参阅下面的代码段(background-color属性未提及,但background-image呈现正常):



div {
    background: url('http://www.planwallpaper.com/static/images/desktop-year-of-the-tiger-images-wallpaper.jpg') top left no-repeat;
    height: 300px;
    background-size: 100%;
}

<div></div>
&#13;
&#13;
&#13;

您的代码的真正问题是图片路径。根据您在屏幕截图中提供的文件夹结构,路径必须是:

background: url('../images/home1.jpg') top left no-repeat;    /*Correct path*/

而不是

background: url('/../images/home1.jpg') top left no-repeat;   /*Wrong path*/

希望有所帮助!!!

答案 2 :(得分:0)

只需将../返回目录路径,因为您当前在CSS文件夹中。

背景:网址(&#39; ../ images / home1.jpg&#39;)左上角不重复;

相关问题