I have the following HTML:
<table>
<tr>
<td class="FINAL">The first cell.</td>
<td class="FINAL">The second cell.</td>
<td class="DRAFT">The third cell.</td>
<td class="DRAFT">The fourth cell.</td>
</tr>
<!-- more rows with the same cell setup -->
</table>
I want to accomplish the following:
- The number of FINAL cells is variable, from 0 to unknown.
- The number of DRAFT cells is variable, from 0 to unknown.
- But there is always at least one cell (i.e. of either FINAL or DRAFT class)
- Adding an additional class to mark the last FINAL (as suggested in the duplication reference) is currently impossible.
- Must be a CSS-only solution.
Select the last p element with the class "FINAL", and style it.- Add a border between the last FINAL and the first DRAFT cell.
My naive CSS beginner's approach to this was the following selector:
td[class~=FINAL]:last-of-type {
// CSS styles ehre
}
but that doesn't select anything except when I indeed have a FINAL td that is the last of its type in a table row.
https://stackoverflow.com/a/8539107/6000494 describes an interesting approach, but that doesn't fully apply here since I cannot guarantee that there will always be a first td element present.
SOLUTION:
The following selector does the trick (https://stackoverflow.com/a/33859457/6000494 pointed me to it):
.FINAL + :not(.FINAL) {
border-left: 1px dotted black;
}
Update:
Edited the original description to a table context, which makes the suggested solution not work (AFAIK). Also clarified some of the constraints.
Update 2 The referenced question has an answer that - albeit not obvious to me - actually solves my problem: https://stackoverflow.com/a/33859457/6000494
A working jsFiddle demonstrates it.
Final update: Described the solution in the question. Can't mark the question as solved myself somehow...
Item 1
Item 2>
Item 3
Item 4>