0

Suppose I have HTML / JSX like this:

<ul>
  <li>First bullet point</li>
  <li>Second bullet point</li>
</ul>

and I want to highlight a range that "spans" multiple list elements "contiguously":

<ul>
  <li>First bullet <mark>point</mark></li>
  <li><mark>Second bullet</mark> point</li>
</ul>

Lastly, I'd like to add behaviour such that hovering over the first <mark> tags will trigger something for the second <mark> tags and vice versa. From the user's perspective, it should look and feel like a single <mark> tag.

Can this be done exclusively with CSS / Tailwind? Based on what I've seen so far, the sibling ~ combinator can only be used on earlier elements to affect later elements. The same appears to be true for the peer class in Tailwind.

If Javascript is required, can someone point me in the right direction? FWIW, this is for a React project so there may be some caveats to manipulating the DOM directly.

jimmy
  • 109
  • 2
  • 9
  • Css can not go backwards up the tree. Is it highlighting all marks that are in the UL? That can be done with CSS. Or if there is multiple marks it only highlights those? If that is the case, you need JavaScript. – epascarello Feb 15 '23 at 19:10
  • @epascarello There may be multiple marks in the `
      `.
    – jimmy Feb 15 '23 at 19:15
  • So if it is `
  • fooxxxxbar
  • ` it should not select the next or prev? – epascarello Feb 15 '23 at 19:21
  • @epascarello Say for example `
  • fooxxxxbar
  • ` was the 3rd list element (after the first two in the example code), then hovering over `xxx` would not affect the prior two marks and vice versa. – jimmy Feb 15 '23 at 19:26
  • So any mark is hovered they all will be highligthed? – epascarello Feb 15 '23 at 19:32