Можете ли вы упорядочить упорядоченные номера списков?
Я пытаюсь найти способ скомпоновать числа в упорядоченном списке, я бы хотел добавить к ним фоновый цвет, радиус границы и цвет, чтобы они соответствовали дизайну, над которым я работаю:
![enter image description here]()
Я предполагаю, что это невозможно, и что мне придется использовать разные изображения для каждого номера i.e.
ol li:first-child{list-style-image:url('1.gif')};
ol li:nth-child(2) {list-style-image:url('2.gif');} etc...
Я думал, что могу использовать спрайты, чтобы сделать это немного лучше, но есть ли более простое решение?
Ответы
Ответ 1
Вы можете сделать это с помощью счетчиков CSS в сочетании с псевдоэлементом :before
:
body {
counter-reset: item;
}
ol {
list-style: none;
}
li {
counter-increment: item;
margin-bottom: 5px;
}
li:before {
margin-right: 10px;
content: counter(item);
background: lightblue;
border-radius: 100%;
color: white;
width: 1.2em;
text-align: center;
display: inline-block;
}
<ol>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ol>
Ответ 2
Я искал что-то другое и нашел этот пример в CodePen;
попробуйте следующее: http://codepen.io/sawmac/pen/txBhK
body {
font-size: 1.2em;
font-family: "Helvetica Neue", Helvetica, sans-serif;
margin: 50px;
}
.custom-counter {
margin: 0;
padding: 0;
list-style-type: none;
}
.custom-counter li {
counter-increment: step-counter;
margin-bottom: 5px;
}
.custom-counter li::before {
content: counter(step-counter);
margin-right: 20px;
font-size: 80%;
background-color: rgb(180, 180, 180);
color: white;
font-weight: bold;
padding: 3px 8px;
border-radius: 11px;
}
<ol class="custom-counter">
<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>