I have - let's say - 4 spans on my page in a block. The content of each is populated by knockout from my viewmodel. Sometimes contents are empty for several spans. I would like to display them in a nice, comma-separated way, taking possible emptyness into account.
I tried the following HTML and CSS.
VERSION 1
It shows commas for empty spans as well
.comma:not(:last-child):after {
content: ", ";
}
<span class="comma">A</span>
<span class="comma">B</span>
<span class="comma"></span>
<span class="comma">D</span>
VERSION 2
It shows a (visually) last comma if last span is empty.
.comma:not(:empty):not(:last-child):after {
content: ", ";
}
<span class="comma">A</span>
<span class="comma">B</span>
<span class="comma">C</span>
<span class="comma"></span>
How could I tweak it to render always correctly, no matter where the gaps are (if any)? I need to support only modern browsers (IE9+ and others).