更改单个列表项项目符号的正确方法
我有这样的 css:
.done {list-style-image:url('images/tick.gif')}
.notdone {list-style-image:url('images/cross.gif')}
和这样的 html:
<ul>
<li class="done">Done</li>
<li class="notdone">Not Done</li>
</ul>
在 IE6 和 FF 上效果很好。 每个 li 项目都有不同的项目符号图像。 但我在 list-style-image 上看到的所有文档都说它应该应用于 ul 标签。
是否有一种正确的或基于标准的方式来做我想做的事情,或者就是这样?
编辑: http://www.w3.org/ TR/CSS21/generate.html
看起来它并没有说我不能在 li 标记上使用 list-style-image,但示例没有显示这一点。
I have css like this:
.done {list-style-image:url('images/tick.gif')}
.notdone {list-style-image:url('images/cross.gif')}
And html like this:
<ul>
<li class="done">Done</li>
<li class="notdone">Not Done</li>
</ul>
Works great on IE6 and FF. Each li item has a different image for the bullet. But all of the docs I see on list-style-image says it should be applied to to the ul tag.
Is there a proper or standards-based way of doing what I am trying to do, or is this it?
EDIT: http://www.w3.org/TR/CSS21/generate.html
It looks like it doesn't say that I CAN'T use list-style-image on an li tag, but the examples don't show that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
将类应用于父标记的原因
我相信您所指的文档是当您希望项目符号遵循某种格式时,这就是在这些情况下 。 由于您有两个图像,每个图像都有自己的项目符号,所以我认为您所做的事情没有任何问题
I believe docs you are referring to is when you want the bullets to follow a certain format, which is why the class is applied at the parent tag
in those cases. Since you have two images that each you want to have its own bullet I see nothing wrong with what you are doing
CSS 2.1 标准 给出了示例,其中
list- style
直接应用于li
。其次:
所以我得出的结论是,直接应用
list-style-type
或list-style-image
来列出项目是可以的,只要你仔细并理解 CSS 规则的级联。The CSS 2.1 standard gives examples where
list-style
is applied directly to anli
.Followed by:
So I would draw the conclusion that it is OK to apply
list-style-type
orlist-style-image
to list items directly, as long as you are careful and understand the cascade of your CSS rule.进行编辑...
如果您查看 default CSS 样式表,您将看到 li 定义如下:
在您提供的链接中,list-style-image 在任何带有 display: list-item 的元素上都有效。 因此,根据标准,你所做的事情是有效的。
Following up to your edit...
If you look at the default style sheet for CSS, you will see that li is defined as follows:
In the link you provided, list-style-image is valid on any element with display: list-item. Therefore, according to the standard, what you are doing is valid.
当涉及到浏览器之间的列表图像间距时,我遇到了不一致的情况。 因此,我通常会跳过整个问题,而是做这样的事情:
最终结果是使用与您最初想要的相同图像的项目符号,但您对实际位置和间距有更多的控制权。 可能需要调整,但这是总体思路。
I've run into inconsistencies when it comes to the spacing of a list-image from browser to browser. As a result, I would usually skip the whole issue, and do something like this instead:
The end result is a bullet using the same images you intended in the first place, but you have much more control over the actual placement and spacing. Tweaking needed probably, but that's the general idea.
我不认为你所做的有什么问题。 你在说什么文档?
I don't see a problem with what you are doing. What docs are you talking about?
理论上,列表中的所有条目都具有相同的项目符号样式。 历史上,这些列表出现在诸如大纲之类的内容中,在任何级别上都有 1、2、3 或 A、B、C,并且将不同的序数类型相互混合是没有意义的。 我不认为按照你的风格去做你正在做的事情有什么问题。 但我不知道CSS是否正确。
In theory all entries in a list have the same bullet style. Those lists are historically found in things like outlines where at any level you have 1,2,3 or A,B,C and it would make no sense to mix the different ordinal types with one another. I don't think there's anything wrong with doing what you are doing stylistically. But I don't know if it is correct CSS.