I have a set of spans, each of which has "white-space: nowrap" to keep them individually non-breaking. I want them to have some visual spacing separating them if they are next to each other on a line, but if the browser decides to line-break, I don't need or want left or right margins at the ends of the lines.
For example:
<div class="container">
<span id="s1">User Option 1</span>
<span id="s2">User Option 2</span>
<span id="s3">User Option 3</span>
<span id="s4">User Option 4</span>
<span id="s5">User Option 5</span>
<span id="s6">User Option 6</span>
<span id="s7">User Option 7</span>
<span id="s8">User Option 8</span>
</div>
In a wide window, I would like to see:
User Option 1 ________ User Option 2 ________ User Option 3 ________ User Option 4
User Option 5 ________ User Option 6 ________ User Option 7 ________ User Option 8
(I have supplied underscore characters to show where I would like some space/padding/margin. I don't want to see the underscores, I want some spacing there.)
But I want the spacing only as needed, and for it to continue to behave nicely when the set of items wraps at different points. So, if the window is somewhat narrower:
User Option 1 ________ User Option 2 ________ User Option 3
User Option 4 ________ User Option 5 ________ User Option 6
User Option 7 ________ User Option 8
Or narrower still:
User Option 1 ________ User Option 2
User Option 3 ________ User Option 4
User Option 5 ________ User Option 6
User Option 7 ________ User Option 8
I know if I just give everything a margin-left, then there is unwanted space reserved at the left of everything:
________ User Option 1 ________ User Option 2 ________ User Option 3
________ User Option 4 ________ User Option 5 ________ User Option 6
________ User Option 7 ________ User Option 8
If I give margin-left within a :not:first-child selector, it actually looks a bit worse:
User Option 1 ________ User Option 2 ________ User Option 3
________ User Option 4 ________ User Option 5 ________ User Option 6
________ User Option 7 ________ User Option 8
If I switch to right-margin, everything always looks good:
User Option 1 ________ User Option 2 ________ User Option 3 ________
User Option 4 ________ User Option 5 ________ User Option 6 ________
User Option 7 ________ User Option 8 ________
because you don't see the right margins that are unneeded.
But there is still a cause for complaint in that these elements are reserving that space off to the right and they therefore will "word-wrap" sooner than necessary because of it, so they still have the unwanted feature of wasting space to the right.
Is there something in CSS that really says what I want to say?
Colloquially, I would say: "margin-right-if-sibling-rendered-to-my-right" ?