I am working on achieving the following goal:
https://i.sstatic.net/xHoIG.png
Elements containing values should have a gray 'ribbon'. Elements with values are given a class selected
, while elements without any value do not have this class.
This is how my HTML code appears:
<div class="row">
<span>.</span>
<span>.</span>
<span class="selected">2</span> <!-- Should be gray & rounded (left) -->
<span class="selected">3</span> <!-- Should be gray -->
<span class="selected">2</span> <!-- Should be gray & rounded (right) -->
<span>.</span>
<span>.</span>
<span class="selected">5</span> <!-- Should be gray & rounded (left) -->
<span class="selected">5</span> <!-- Should be gray & rounded (right) -->
<span>.</span>
</div>
<div class="row">
...
</div>
In order to achieve the gray ribbon effect, I believe I need the following CSS rules:
- All elements with the class
selected
should have a gray background. This part is straightforward. - The first and last element of a group of adjacent elements with the class 'selected' should have rounded corners. This part presents a challenge.
To the best of my understanding, there is no CSS selector like :first-of-class
. Additionally, even if there were one, it would not suffice because multiple 'ribbons' can appear on the same line. Ideally, I would require something similar to :first-adjacent-sibling-of-class
.
Is there a way to accomplish this using pure CSS, or will I need to utilize JavaScript?