list-style-image失效background替换方法

使用css+html制作网页时,经常会出现css代码在某浏览器没有效果的情况,如list-style-image代码就经常不能显示出图标,有些时候是因为使用了float的原因,有些时候却难以发现是什么原因。解决的方法一般是使用background背景图片的方法。

如以下css代码:

#sidebar ul {margin:15px 0;}
#sidebar ul li {line-height:1.5em; padding-left:10px; background:url(images/post.jpg) no-repeat center left; font-size:12px; white-space:nowrap;overflow:hidden; width:17em;}
背景图片定位时使用center是因为我的post.jpg图标很小,不能与文字水平居中显示;

关键词: css