list-style-image的替代方案

xyzyz 2009-08-12 01:22:10
非常的郁闷, IE7下list-style-image好像是完全没有效果,在网上搜索了很久也是这么说的, 虽然有解决方法, 但普遍是比较复杂, 所以就另外找了一个方法,就是使用背景图像的.问题来了:
我写的CSS代码如下:
#sidebar #widget_posts  ul li, #sidebar #widget_comments ul li, #sidebar #widget_categories ul li {
background: url(images/list_icon.gif) no-repeat left;
/*list-style-type: circle;*/
padding-left:10px;
}

以上是实现在li前添加一个小图标.
在FF下测试一切正常, 但是在IE下就很奇怪了,
#sidebar #widget_comments ul li
#sidebar #widget_categories ul li
这两行代码控制的每一行li都可以正常的现实li的小图标
但是:
#sidebar #widget_posts ul li
这行代码下只有最后一行的li显示出了小图标, 百思不得其解, 希望大家能够帮到我.
源代码是这样的:
<div id="sidebar">
<ul>
<?php
if (is_home()) {
$posts_widget_title = 'Random Posts';
} else {
$posts_widget_title = 'Recent Posts';
}
?>
<li id="widget_posts">
<h2><?php echo $posts_widget_title; ?></h2>
<ul>
<?php
if (is_single()) {
$posts = get_posts('numberposts=6&&orderby=post_date');
} else {
$posts = get_posts('numberposts=6&&orderby=rand');
}
foreach($posts as $post) {
setup_postdata($post);
echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
}
$post = $posts[0];
?>
</ul>
</li>
<!-- end of the random/recent posts -->

<!-- start of the widget_comments -->
<li id="widget_comments">
<h2>Recent Comments</h2>
<ul><?php get_recent_comments(); ?></ul>
<!--<ul><?php wp_recentcomments(); ?></ul>-->
</li>
<!-- end of the widget_comments -->

<!-- start of the widget_categories -->
<li id="widget_categories">
<h2>Categories</h2>
<ul><?php wp_list_categories('show_count=1&title_li=') ?></ul>
</li>
<!-- end of the widget_categories -->
</ul>
</div>

关键部分动态生成的html代码如下:
<!-- start of the random/recent posts -->
<li id="widget_posts">
<h2>Random Posts</h2>

<ul>
<li><a href="http://127.0.0.1/wordpress/?p=3">寄语新博开张</a></li><li><a href="http://127.0.0.1/wordpress/?p=37">生活方式</a></li><li><a href="http://127.0.0.1/wordpress/?p=101">理清思绪</a></li><li><a href="http://127.0.0.1/wordpress/?p=102">One year</a></li><li><a href="http://127.0.0.1/wordpress/?p=33">沟通从心开始</a></li><li><a href="http://127.0.0.1/wordpress/?p=12">弟弟启程了</a></li> </ul>
</li>
<!-- end of the random/recent posts -->

<!-- start of the widget_comments -->

<li id="widget_comments">
<h2>Recent Comments</h2>
<ul> <li><a href="http://127.0.0.1/wordpress/?p=96#comment-85" title="信息周刊:车轮上的携程们, 2009年07月31日">admin</a>: @admin 看下这个显示最新评论的插件如何撒?</li>
<li><a href="http://127.0.0.1/wordpress/?p=96#comment-83" title="信息周刊:车轮上的携程们, 2009年07月31日">admin</a>: let’s have a try</li>
</ul>
<!-- end of the widget_comments -->

<!-- start of the widget_categories -->
<li id="widget_categories">
<h2>Categories</h2>
<ul> <li class="cat-item cat-item-39"><a href="http://127.0.0.1/wordpress/?cat=39" title="查看 WEB2.0 下的所有文章">WEB2.0</a> (2)

</li>
<li class="cat-item cat-item-43"><a href="http://127.0.0.1/wordpress/?cat=43" title="查看 wordpress 下的所有文章">wordpress</a> (3)
</li>
<li class="cat-item cat-item-1"><a href="http://127.0.0.1/wordpress/?cat=1" title="查看 未分类 下的所有文章">未分类</a> (21)
</li>
</ul>
</li>
<!-- end of the widget_categories -->
...全文
1303 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zw393 2009-08-16
  • 打赏
  • 举报
回复
最笨的方式:将list的style设置为none,然后在要求的li元素中加入<img/>
还有一种方案就是在css中将list的style设置为none,然后在js中修改html文档对象树,在要求的li元素中加入<img/>
浴火_凤凰 2009-08-13
  • 打赏
  • 举报
回复
楼主是做widget开发的吗???
xyzyz 2009-08-12
  • 打赏
  • 举报
回复
who can help me?
xyzyz 2009-08-12
  • 打赏
  • 举报
回复
刚刚测试了下
的确如果就是上面的html代码的话
每行都会有图标
但是使用动态生成的时候就有问题了..
hookee 2009-08-12
  • 打赏
  • 举报
回复
以下ie8 ie6测下来 三段每行都有图标的

<style>
#sidebar #widget_posts ul li, #sidebar #widget_comments ul li, #sidebar #widget_categories ul li {
background:url(images/list_icon.gif) no-repeat left;
/*list-style-type: circle;*/
padding-left:10px;
}
</style>
<div id="sidebar">
<ul>
<li id="widget_posts">
<h2>Random Posts</h2>

<ul>
<li><a href="http://127.0.0.1/wordpress/?p=3">寄语新博开张</a></li>
<li><a href="http://127.0.0.1/wordpress/?p=37">生活方式</a></li>
<li><a href="http://127.0.0.1/wordpress/?p=101">理清思绪</a></li>
<li><a href="http://127.0.0.1/wordpress/?p=102">One year</a></li>
<li><a href="http://127.0.0.1/wordpress/?p=33">沟通从心开始</a></li>
<li><a href="http://127.0.0.1/wordpress/?p=12">弟弟启程了</a></li> </ul>
</li>
<!-- end of the random/recent posts -->

<!-- start of the widget_comments -->

<li id="widget_comments">
<h2>Recent Comments</h2>
<ul> <li><a href="http://127.0.0.1/wordpress/?p=96#comment-85" title="信息周刊:车轮上的携程们, 2009年07月31日">admin</a>: @admin 看下这个显示最新评论的插件如何撒?</li>
<li><a href="http://127.0.0.1/wordpress/?p=96#comment-83" title="信息周刊:车轮上的携程们, 2009年07月31日">admin</a>: let’s have a try</li>
</ul>
<!-- end of the widget_comments -->

<!-- start of the widget_categories -->
<li id="widget_categories">
<h2>Categories</h2>
<ul> <li class="cat-item cat-item-39"><a href="http://127.0.0.1/wordpress/?cat=39" title="查看 WEB2.0 下的所有文章">WEB2.0</a> (2)

</li>
<li class="cat-item cat-item-43"><a href="http://127.0.0.1/wordpress/?cat=43" title="查看 wordpress 下的所有文章">wordpress</a> (3)
</li>
<li class="cat-item cat-item-1"><a href="http://127.0.0.1/wordpress/?cat=1" title="查看 未分类 下的所有文章">未分类</a> (21)
</li>
</ul>
</li>

</ul>
</div>
elephant0318 2009-08-12
  • 打赏
  • 举报
回复
<style>
#widget_posts ul li, #widget_comments ul li, #widget_categories ul li {
/*list-style-type: circle;*/
padding-left:10px;
background-image: url(images/copy.gif);
background-repeat: no-repeat;
background-position: left;
}
</style>
<!-- start of the random/recent posts -->
<li id="widget_posts">
<h2>Random Posts</h2>

<ul>
<li><a href="http://127.0.0.1/wordpress/?p=3">寄语新博开张</a></li><li><a href="http://127.0.0.1/wordpress/?p=37">生活方式</a></li><li><a href="http://127.0.0.1/wordpress/?p=101">理清思绪</a></li><li><a href="http://127.0.0.1/wordpress/?p=102">One year</a></li><li><a href="http://127.0.0.1/wordpress/?p=33">沟通从心开始</a></li><li><a href="http://127.0.0.1/wordpress/?p=12">弟弟启程了</a></li> </ul>
</li>
<!-- end of the random/recent posts -->

<!-- start of the widget_comments -->

<li id="widget_comments">
<h2>Recent Comments</h2>
<ul> <li><a href="http://127.0.0.1/wordpress/?p=96#comment-85" title="信息周刊:车轮上的携程们, 2009年07月31日">admin</a>: @admin 看下这个显示最新评论的插件如何撒?</li>
<li><a href="http://127.0.0.1/wordpress/?p=96#comment-83" title="信息周刊:车轮上的携程们, 2009年07月31日">admin</a>: let’s have a try</li>
</ul>
</li>
<!-- end of the widget_comments -->

<!-- start of the widget_categories -->
<li id="widget_categories">
<h2>Categories</h2>
<ul> <li class="cat-item cat-item-39"><a href="http://127.0.0.1/wordpress/?cat=39" title="查看 WEB2.0 下的所有文章">WEB2.0</a> (2)

</li>
<li class="cat-item cat-item-43"><a href="http://127.0.0.1/wordpress/?cat=43" title="查看 wordpress 下的所有文章">wordpress</a> (3)
</li>
<li class="cat-item cat-item-1"><a href="http://127.0.0.1/wordpress/?cat=1" title="查看 未分类 下的所有文章">未分类</a> (21)
</li>
</ul>
</li>
<!-- end of the widget_categories -->

61,115

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧