I needed to create a list with a custom index list that is vertically centered for the contents of the list items.
Since I use flex already, I thought it was easiest to give a list item a display:flex;
and stylize it. This works, but as soon as the list-item contains other items, it gets messed up . As you can see in the example below .
What is the best way to vertically center a list index?
- Updated example -
ol { list-style: none; padding: 0; width: 200px; } ol > li { display: flex; margin-top: 20px; align-items: center; } ol > li:before { color: red; content: attr(data-count)' ›'; flex display: block; flex-shrink: 0; text-align: right; min-width: 24px; padding-right: 5px; }
<ol> <li data-count="1">Lorem ipsum dolor sit amet, consectetur adipisicing elit</li> <li data-count="10">Lorem ipsum dolor sit <span>amet</span>, consectetur adipisicing elit</li> <li data-count="999">Lorem ipsum dolor sit amet, consectetur adipisicing elit</li> </ol>
source share