WebSS
WebSS

Reputation: 63

How do I make the marker the same everywhere and center the numbers?

I was working on creating a list with a custom marker and I had a question. How do insert a marker in the indent for the first line? How do insert a marker in the indent for the first line?

li {
    list-style-type: none;
    /* Vertically centered */
    display: flex;

    text-indent: 30px;
}

ul {
    counter-reset: item;
    list-style-position: inside;
}

li:before {
    text-indent: 12px;
    /* Fixed width and centered */
    width: 15px;
    display: flex;
    justify-content: right;
    height: 15px;
    margin: 6px;
    content: counter(item) ". ";
    counter-increment: item;
    font-size: 80%;
    background-color: black;
    color: white;
    background-size: 8px 10px;
    padding: 3px;
    border-radius: 30px;
    font-weight: bold;
    margin-right: 0px 4px 3px 0px;
}
<div style="max-width: 30%; text-align: justify;">
    <ul>
        <li>text texttetex ttexttexttex ttexttexttextte xttexttextxt textte xttextex ttexttexttex ttexttexttextte xttexttextttextt exttexttextte xttexttexttext</li>
        <li>texttextt exttextt exttexttexttexttexttexttexttetex ttexttexttex ttexttexttextte xttexttextxttextte xttexttext texttexttexttext</li>
        <li>texttexttex ttexttexttex ttextex ttexttexttex ttexttexttextte xttexttextttexttextte xttexttexttexttexttexttexttexttextte xttext</li>
        <li>  xttexttexttexttex ttextt extex ttexttexttex ttexttexttextte xttexttextttextte xttext texttexttex ttextte xttexttexttex ttexttext</li>
    </ul>
   </div>

Upvotes: 0

Views: 88

Answers (1)

amedina
amedina

Reputation: 3456

I added the needed properties here. Read the comments:

li {
  background-position: top -0px left -0px;
  background-size: 14px 14px;
  list-style-type: none;
  
  /* Vertically centered */
  display: flex;
  align-items: center;
}

ul {
  counter-reset: item;
}

li:before {
  /* Fixed width and centered */
  width: 40px;
  display: flex;
  justify-content: center;
  
  margin: 6px;
  content: counter(item) ". ";
  counter-increment: item;
  font-size: 120%;
  background-color: black;
  color: white;
  background-size: 8px 10px;
  padding: 3px;
  border-radius: 12px;
  font-weight: bold;
  margin-right: 0px 4px 3px 0px;
}

Live demo here.

Upvotes: 1

Related Questions