I need top-bottom borders for list items. The item’s decoration needs to be customized and if element text is too long it should not be under the element decoration. I can’t figure it out.
div {
width: 20%;
}
ul {
list-style-position: inside;
list-style-type: none;
}
li {
border-top: 1px solid;
padding: 0.1em 0.3em;
}
li span {
position: relative;
left: 1em;
}
li::before {
content: "2022";
color: #800000;
font-size: 1em;
vertical-align: middle;
line-height: 1em;
width: 10px;
}
li:last-of-type {
border-bottom: 1px solid;
}
<div>
<ul>
<li><span>foo</span></li>
<li><span>bar</span></li>
<li><span>very long sentence is here which should be nicely aligned</span></li>
</ul>
</div>
2
Answers
If you set the position of your pseudo elements to absolute you get what you want:
Try displaying the
li
asflex
.Remove the
width
from theli