图像不显示在div中

时间:2014-05-02 23:42:22

标签: html css html5

我试图在按钮div中显示背景图像,但它没有显示。

将背景图像更改为背景颜色,并在图像的正确位置显示颜色。

我在这里画一个空白:jsfiddle

这是一段代码:

.strawberry {
height:65px;
width:100%;
background-image: url('src/bg_button.jpg');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center; 
overflow:hidden;
}

我是html5的新手,所以请保持温和。

2 个答案:

答案 0 :(得分:2)

您可能不在正确的文件夹中试试这个:

.strawberry {
    height: 65px;
    width: 100%;
    background: url("../src/bg_button.jpg");
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center;
    overflow: hidden;
}

答案 1 :(得分:0)

在jsfiddle中,需要从网络上的某个地方获取以这种方式引用的图像。当我在Chrome中加载您的小提琴时,我发现404找不到错误:

  

无法加载资源:服务器响应状态为404   (未找到)http://fiddle.jshell.net/m6AnC/13/show/src/bg.png     http://fiddle.jshell.net/m6AnC/13/show/src/header.jpg     http://fiddle.jshell.net/m6AnC/13/show/src/bg_button.jpg

请参阅:Adding images in JSfiddle