我有一个类型设置为“A”的 html 有序列表
<ol type="A">...</ol>
因此,每个列表项将以 A、B、C 等开头。
我想将 A、B、C 字母设置为粗体。我试过设置 font-weight:bold; 通过css,但它没有用。关于如何做到这一点的任何建议?
我有一个类型设置为“A”的 html 有序列表
<ol type="A">...</ol>
因此,每个列表项将以 A、B、C 等开头。
我想将 A、B、C 字母设置为粗体。我试过设置 font-weight:bold; 通过css,但它没有用。关于如何做到这一点的任何建议?
有点作弊,但它有效:
HTML:
<ol type="A" style="font-weight: bold;">
<li><span>Text</span></li>
<li><span>More text</span></li>
</ol>
CSS:
li span { font-weight: normal; }
作为替代和卓越的解决方案,您可以在 before 元素中使用自定义计数器。它不涉及额外的 HTML 标记。CSS 重置应该与它一起使用,或者至少从ol
元素 ( list-style-type: none, reset margin
) 中删除样式,否则该元素将有两个计数器。
<ol>
<li>First line</li>
<li>Second line</li>
</ol>
CSS:
ol {
counter-reset: my-badass-counter;
}
ol li:before {
content: counter(my-badass-counter, upper-alpha);
counter-increment: my-badass-counter;
margin-right: 5px;
font-weight: bold;
}
一个例子:http: //jsfiddle.net/xpAMU/1/
您确定您正确应用了样式,还是没有其他样式表干扰您的列表?我试过这个:
<ol type="A">
<li><span class="label">Text</span></li>
<li><span class="label">Text</span></li>
<li><span class="label">Text</span></li>
</ol>
然后在样式表中:
ol {font-weight: bold;}
ol li span.label {font-weight:normal;}
它加粗了A
,B
等C
而不是文本。
(在 Opera 9.6、FF 3、Safari 3.2 和 IE 7 中测试过)
我知道这个问题有点老了,但它仍然出现在很多谷歌搜索中。我想添加一个不涉及编辑样式表的解决方案(在我的情况下,我没有访问权限):
<ol type="A">
<li style="font-weight: bold;">
<p><span style="font-weight: normal;">Text</span></p>
</li>
<li style="font-weight: bold;">
<p><span style="font-weight: normal;">More text</span></p>
</li>
</ol>
你也可以这样做:
ol {
font-weight: bold;
}
ol > li > * {
font-weight: normal;
}
所以你的 HTML 中没有“样式”属性
你也可以这样做:
<ol type="A" style="font-weight: bold;">
<li style="padding-bottom: 8px;">****</li>
这是初学者的简单代码。
此代码已在“Mozilla、chrome 和 edge..
另一个更短的解决方案是利用li::marker
现在广泛支持的. 像这样:
ol li::marker {
font-weight: bold;
}