英文:
How to style the number together with the item in an ordered list?
问题
当我为有序列表项定义一个.active
类时,项目编号没有样式。
li.active {
background-color: #c5ecbe;
width: 14em;
padding: 3px 6px;
border-radius: 8px;
}
如何同时为项目编号设置样式?
英文:
When I define an .active
class for an ordered list item, the item number is not styled.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
li.active {
background-color: #c5ecbe;
width: 14em;
padding: 3px 6px;
border-radius: 8px;
}
<!-- language: lang-html -->
<ol>
<li id="i1" class="active">Item 1</li>
<li id="i2">Item 2</li>
<li id="i3">Item 3</li>
</ol>
<!-- end snippet -->
How to style the number together with the item?
答案1
得分: 0
需要添加一些CSS和CSS计数器。
ol {
list-style: none;
counter-reset: item;
}
li {
counter-increment: item;
margin-bottom: 5px;
}
li:before {
content: counter(item) ".";
width: 15px;
margin-right: 5px;
text-align: center;
display: inline-block;
}
li.active {
background-color: #212121;
width: 14em;
padding: 3px 6px;
border-radius: 8px;
}
<ol>
<li id="i1" class="active">Item 1</li>
<li id="i2">Item 2</li>
<li id="i3">Item 3</li>
</ol>
英文:
Need to add some css and css counter
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
ol {
list-style: none;
counter-reset: item;
}
li {
counter-increment: item;
margin-bottom: 5px;
}
li:before {
content: counter(item) ".";
width: 15px;
margin-right: 5px;
text-align: center;
display: inline-block;
}
li.active {
background-color: #212121;
width: 14em;
padding: 3px 6px;
border-radius: 8px;
}
<!-- language: lang-html -->
<ol>
<li id="i1" class="active">Item 1</li>
<li id="i2">Item 2</li>
<li id="i3">Item 3</li>
</ol>
<!-- end snippet -->
答案2
得分: 0
使用 list-style-position: inside
li.active {
background-color: #212121;
width: 14em;
padding: 3px 6px;
border-radius: 8px;
}
ol {
list-style-position: inside;
}
<ol>
<li id="i1" class="active">Item 1</li>
<li id="i2">Item 2</li>
<li id="i3">Item 3</li>
</ol>
英文:
Use list-style-position: inside
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
li.active {
background-color: #212121;
width: 14em;
padding: 3px 6px;
border-radius: 8px;
}
ol {
list-style-position: inside
}
<!-- language: lang-html -->
<ol>
<li id="i1" class="active">Item 1</li>
<li id="i2">Item 2</li>
<li id="i3">Item 3</li>
</ol>
<!-- end snippet -->
答案3
得分: -2
li.active {
background-color: #212121;
width: 14em;
padding: 3px 6px;
border-radius: 8px;
font-size: 1.5em;
color: red;
}
<ol>
<li id="i1" class="active">Item 1</li>
<li id="i2">Item 2</li>
<li id="i3">Item 3</li>
</ol>
英文:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
li.active {
background-color: #212121;
width: 14em;
padding: 3px 6px;
border-radius: 8px;
font-size: 1.5em;
color: red;
}
<!-- language: lang-html -->
<ol>
<li id="i1" class="active">Item 1</li>
<li id="i2">Item 2</li>
<li id="i3">Item 3</li>
</ol>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论