[html] 주문 목록 번호의 스타일을 지정할 수 있습니까?

순서가 지정된 목록의 번호에 스타일을 지정하려고합니다. 배경색, 테두리 반경 및 색상을 추가하여 작업중인 디자인과 일치하도록하고 싶습니다.

여기에 이미지 설명 입력

나는 그것이 불가능하다고 생각하고 각 숫자에 대해 다른 이미지를 사용해야 할 것입니다.

ol li:first-child {list-style-image:url('1.gif')};
ol li:nth-child(2) {list-style-image:url('2.gif');}
etc...

더 간단한 해결책이 있습니까?



답변

유사 요소 와 함께 CSS 카운터를 사용하여이 작업을 수행 할 수 있습니다 :before.

 ol {
   list-style: none;
   counter-reset: item;
 }
 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>


답변

저는 다른 것을 찾고 있었고 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>


답변