用CSS编写源代码时无法看到图像

时间:2014-01-24 22:03:47

标签: css

在浏览器中查看页面时,我看不到此图像。

我的CSS代码是;

#bar {  
background:url("/Users/Macbook/Desktop/test website/images/bar.png");
}

,div部分是;

<div id="bar">
</div>

你能看出为什么我在浏览器中看不到任何内容,我犯了错误。

谢谢你

2 个答案:

答案 0 :(得分:5)

你需要在div上放一个大小。它的大小不存在,因为它没有内容......它不使用背景来确定大小,因为它能够重复等等。

您可以使用以下内容在元素上设置height

#bar {
 background:url("/Users/Macbook/Desktop/test website/images/bar.png");
 height:300px; /*Use the value you want can be the height of the background image*/
}

答案 1 :(得分:0)

试试这个:

在css中将宽度和高度设置为任意值,例如:

#bar {  
background:url("/Users/Macbook/Desktop/test website/images/bar.png") 
width: 600px;
height: 800px;
}

另外,在你的html中,向div中添加一些内容,例如不间断的空格&nbsp;

<div id="bar">&nbsp;</div>
相关问题