[英]How do I make a lettered ordered list in HTML using CSS Style (not using type)
[英]How to do css style for ordered list numbers?
我尝试使用 CSS 更改有序列表编号的样式,但我得到了一些错误的结果。
<ol>
<li>This is the first item</li>
<li>This is the second item</li>
<li>This is the third item</li>
<li>This is the fourth item</li>
<li>This is the fifth item</li>
<li>This is the sixth item</li>
</ol>
CSS
ol li {
counter-increment: step-counter;
margin-bottom: 10px;
list-style-type: none;
}
ol li::before {
content: counter(step-counter);
margin-right: 5px;
font-size: 80%;
background-color: rgb(0,200,200);
color: white;
font-weight: bold;
padding: 3px 8px;
border-radius: 15px;
}
上面的代码显示了 2 个列表编号(一个默认值,另一个是我定义的样式)。 output 就像
那么,为什么它会出现两次。 请帮助一次性获得(第二个是我定义的风格)
custom-counter
是一个无效的选择器,即使它是有效的,它也不会指向任何内容。 只需删除整个规则集,然后添加list-style-type: none;
到<ol>
如下:
ol {list-style-type: none;}
将position:relative
分配给所有<li>
并将position:absolute
分配给每个li::before
,以便对与文本的所有项目符号距离进行精细控制。
li {
position: relative;
...
}
li::before {
...
position: absolute;
top: -1px;
/* Adjust < -number | number+ > */
left: -32px;
...
:root { font: 400 16px/1.25 Verdana } ol { list-style-type: none; } ol li { counter-increment: step-counter; position: relative; margin: 10px 0 0 0; } ol li::before { content: counter(step-counter); display: block; position: absolute; top: -1px; /* Adjust < -number | number+ > */ left: -32px; width: 1.25rem; height: 1.25rem; line-height: 1.25rem; background-color: rgb(0, 200, 200); color: white; font-weight: bold; font-size: 0.8rem; text-align: center; border-radius: 15px; }
<ol> <li>This is the first item</li> <li>This is the second item</li> <li>This is the third item</li> <li>This is the fourth item</li> <li>This is the fifth item</li> <li>This is the sixth item</li> </ol>
我对列表编号样式的简单解决方案:将 <li> 内的所有内容放在一个跨度中,然后将跨度设置为不同于 <li> 本身的样式。
HTML:
<ol>
<li><span>List item</span></li>
<li><span>List item</span></li>
<li><span>List item</span></li>
</ol>
CSS:
li {
color: red;
font-weight: bold;
}
li span {
color: black;
font-weight: normal;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.