0

I have a table that looks like this...

<h4>Section title</h4>

<table>
    <tbody>
        <tr class="myrow">
        </tr>
    </tbody>
</table>

I am trying to use CSS to target the H4 in realtion to the table below it. I have tried...

    h4:has(+ .tr.myrow) {
        color:red;
    }

This isn't working, where am I going wrong?

UPDATE

I am now attempting to achieve this using jQuery instead like this...

$(".myrow").prev().prev().hide();

Still not seeing what I expect, can you stack .prev like this?

jsmitter3
  • 411
  • 1
  • 4
  • 15

1 Answers1

1

You can do this using :has provided you are happy that the browsers you are targetting implement it (most major browsers do, but FF puts it behind a flag at the moment).

The + needs to target the element immediately following, this is a table element.

The td doesn't have a dot in front of it - it's a tag not a class.

<h4>Section title</h4>

<table>
  <tbody>
    <tr class="myrow">
    </tr>
  </tbody>
</table>
<style>
  h4:has(+ table tr.myrow) {
    color: red;
  }
</style>
A Haworth
  • 30,908
  • 4
  • 11
  • 14