2012-01-30 68 views
0

工作,我需要设置我使用background: url('images/something.jpg')[..];奇怪的CSS问题 - 背景属性不无图像高度

铁图像height每次。

HTML:

<div class="someImage"></div> 

CSS:

.someImage { 
    background: url('images/something.jpg') no-repeat top; 
} 

上面的例子应该工作...但不能显示图像,直到我添加图像height属性的CSS样式类:

.someImage { 
    background: url('images/something.jpg') no-repeat top; 
    height: 25px; 
} 

然后我的图片出现在网站上...

为什么它会发生?

回答

3

因为没有内容,div没有高度,没有背景图片。

1

由于您的div是空的它没有高度..

您使用的图片应用为背景,所以它不会影响大小..它只是适合任何空间,可在格。

当您明确设置高度时,您将为图像创建空间..