I need to display a list of tags horizontally and add a comma after each item except for the last one.
Here is how I can achieve this using CSS:
ul.tags {
list-style: none;
}
ul.tags > li {
display: inline;
}
ul.tags > li:after {
content: ", ";
}
ul.tags > li:last-of-type:after {
content: "";
}
I also considered combining the last two rules like this:
ul.tags > li:not(ul.tags > li:last-of-type):after {
content: ", ";
}
Unfortunately, this method did not work as expected. Is there another way to select all but the last <li>
elements in the list?