简体   繁体   English

如何为有序列表编号执行 ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ 样式?

[英]How to do css style for ordered list numbers?

I try to change the style of the Ordered list numbers using CSS, but I got some wrong outcomes.我尝试使用 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 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;
}

The above code displays 2 List numbers (One Default and the other is my defined style).上面的代码显示了 2 个列表编号(一个默认值,另一个是我定义的样式)。 The output is like output 就像

    1. This is my first item这是我的第一个项目
    1. This is my second item这是我的第二个项目

So, why it occurs double times.那么,为什么它会出现两次。 Please help to get that as single time (the second one is my defined style)请帮助一次性获得(第二个是我定义的风格)

custom-counter is an invalid selector and even if it was valid, it would be pointing to nothing. custom-counter是一个无效的选择器,即使它是有效的,它也不会指向任何内容。 Just remove that whole ruleset and then add list-style-type: none;只需删除整个规则集,然后添加list-style-type: none; to the <ol> as in:<ol>如下:

ol {list-style-type: none;}

Assign position:relative to all <li> and position:absolute to each li::before in order to have granular control over all bullet distances from text.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>

My simple solution to style list numbers: put everything inside the <li> in a span, then style the span differently than the <li> itself.我对列表编号样式的简单解决方案:将 <li> 内的所有内容放在一个跨度中,然后将跨度设置为不同于 <li> 本身的样式。

HTML: HTML:

<ol>
<li><span>List item</span></li>
<li><span>List item</span></li>
<li><span>List item</span></li>
</ol>

CSS: CSS:

li {
  color: red;
  font-weight: bold;
}

li span {
  color: black;
  font-weight: normal;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 CSS 样式(不使用类型)在 HTML 中制作字母有序列表 - How do I make a lettered ordered list in HTML using CSS Style (not using type) 你可以在 javascript 中设置有序列表编号的样式吗? 如果是这样,如何? - Can you style ordered list numbers in javascript? If so, how? 您可以设置有序列表编号的样式吗? - Can you style ordered list numbers? 您如何获取要在IE中左侧显示的有序列表的编号? - How do you get the numbers of an ordered list to show on the left in IE? 如何仅使用css在html中彩色下罗马顺序表样式? - How to COLOR lower-roman ordered list style in html with just css? 使用有序列表时,如何将样式仅应用于悬停的列表项,而不应用于父项? - When using an ordered list, how do I apply a style to ONLY the hovered list item, but not the parent? 有序列表和文本内容:如何在 css 中将大字体大小的数字与右侧的小文本居中 - Ordered List and text content: How to Left center the numbers in large font size against small text on the right in css 如何使用 CSS 为有序列表项编号添加静态字符串前缀? - How can I prefix ordered list item numbers with a static string using CSS? "如何自定义有序列表中的数字?" - How can you customize the numbers in an ordered list? 如何在有序列表中组合数字和字母? - How to combine numbers and letters in ordered list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM