I have a <ul>
element, with list items as such:
<ul>
<li class="list__item">
<span class="list__quantity">3</span>
<span class="list__unit">Kg</span>
<span class="list__name">Tomatos</span>
</li>
<li class="list__item">
<span class="list__quantity">3</span>
<span class="list__unit">Kg</span>
<span class="list__name">Cucmbers</span>
</li>
</ul>
I want to have a text-decoration: line-through
that spans across an entire list item. I’ve tried:
.list__item {
display: flex;
margin-bottom: 10px;
width: 100%;
text-decoration: line-through;
}
But my list looks like this:
I want the line to be continuous, spanning the whole list item.
Is that possible?
3
Answers
Don’t use
line-through
, use a pseudo-element positioned over thespan
sremoved image
You could use
::before
pseudo element for this. Only drawback is you will have to limit the width of li elements tomax-content
or you can set the values manually for width of the line.Alternatively you can use the psuedo element on the span itself. That will require some hit and trial to get the exact width and position as per your entire list-data. First method is a bit easier and minimalist but you can go for second one if you need the
li
to bewidth:100%
You can try below. This adds whitespace on right side of span except the last span. Note you have to remove existing padding/margin from the span.
screenshot