IE6和IE7中的CSS背景图像不一致

时间:2010-04-16 11:54:07

标签: css internet-explorer-6 internet-explorer-7

我有一个通过javascript生成的span,其css类如下:

.class1{  
  width:25px;
  height:25px;
  background-image: url(pic.png);
  background-repeat:no-repeat;
  background-position: center; 
  cursor:pointer;
  margin-left:10px;
 }  

问题出现了,在html页面上,我可以在IE7中看到指针 - 光标,而不是跨越背景图像。

在IE6中,两者都显示,没问题。

1 个答案:

答案 0 :(得分:3)

根据定义,Span是一个内联元素,尝试将display:block;display:inline-block;添加到.class1。同时添加图片的heightwidth

像这样:

.class1{  
  width:25px;
  height:25px;
  background-image: url(pic.png);
  background-repeat:no-repeat;
  background-position: center; 
  cursor:pointer;
  margin-left:10px;

display:block; /*or inline-block*/
height:100px;
width:100px; /*img height and width*/
 }