[英]How to put different bullets for different items (li) in html list (ol/ul)?
I would like li that have "ok" class to display a checked mark and li that have "ko" class to display a cross mark.我希望具有“ok” class 的 li 显示一个选中标记,而具有“ko” class 的 li 显示一个十字标记。
I am displaying thumbs up by default only for debug purpose in this example:在此示例中,我默认仅出于调试目的显示竖起大拇指:
ol { padding-left: 30px; list-style: none; } li:before { margin-left: -20px; margin-right: 10px; content: '\1F44D'; }.ok li:before { content: '\2714'; }.ko li:before { content: '\274C'; }
<ol id="opponentsOfCivOL"> <li class="ok">1</li> <li class="ok">1</li> <li class="ok">1</li> <li class="ko">1</li> <li class="ok">1</li> </ol>
What am I missing to make this work?我缺少什么来完成这项工作?
Change your CSS for .ok
and .ko
.将 CSS 更改为.ok
和.ko
。 Instead of it being .ok li:before
it should be li.ok:before
.而不是.ok li:before
它应该是li.ok:before
。
li.ok
is read as find all elements with tag li
with class name ok
. li.ok
被读作 find all elements with tag li
with class name ok
。
Whereas .ok li
is read as find all elements with class name ok
and all elements with tagname li
inside it.而.ok li
被读取为查找所有具有 class 名称的元素ok
以及其中带有标记名li
的所有元素。
li.ok:before {
content: '\2714';
}
li.ko:before {
content: '\274C';
}
The classes "ok" and "ko" belong to the lis and have to be in the the css after "li". “ok”和“ko”类属于 lis,必须在“li”之后的 css 中。
Working example :工作示例:
ol { padding-left: 30px; list-style: none; } li:before { margin-left: -20px; margin-right: 10px; content: '\1F44D'; } li.ok:before { content: '\2714'; } li.ko:before { content: '\274C'; }
<ol id="opponentsOfCivOL"> <li class="ok">1</li> <li class="ok">1</li> <li class="ok">1</li> <li class="ko">1</li> <li class="ok">1</li> </ol>
Your css selector for li
with the classes is incorrect.您的li
与类的 css 选择器不正确。 See more here在这里查看更多
ol { padding-left: 30px; list-style: none; } li:before { margin-left: -20px; margin-right: 10px; content: '\1F44D'; } li.ok:before { content: '\2714'; } li.ko:before { content: '\274C'; }
<ol id="opponentsOfCivOL"> <li class="ok">1</li> <li class="ok">1</li> <li class="ok">1</li> <li class="ko">1</li> <li class="ok">1</li> </ol>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.