Imagine a scenario where hovering over any row within group 1 changes the color of all rows within that same group. Now, extend this concept to apply to an unlimited number of groups, denoted by N
.
Let's consider having 300 groups, each consisting of 3 rows. How can we implement this highlighting effect for every group without manually duplicating the CSS rule 300 times?
Is it feasible to achieve this purely with CSS?
.parent:has(.group-1:hover) .group-1 {
background-color: blue;
}
<body class="parent">
<p class="group-1">Group 1</p>
<p class="group-1">Group 1</p>
<p class="group-1">Group 1</p>
<p class="group-2">Group 2</p>
<p class="group-2">Group 2</p>
<p class="group-2">Group 2</p>
<p class="group-3">Group 3</p>
<p class="group-3">Group 3</p>
<p class="group-3">Group 3</p>
</body>