Css select all descendants (asterisks) of elements with class

I want to highlight all descendant elements of the class = "x" element as follows:

<!DOCTYPE html>
<html>
<head>
  <style type="text/css">
    .x * {
      color: red;
    }
  </style>
</head>
<body>
  a
  <p>
    b
     <p class="x">
        c
        <p> should be red </p> foo
     </p>
  </p>
</body>
</html>

which, unfortunately, does not apply to these elements. nor *.x *does it.

what am I doing wrong?

+3
source share
2 answers

You can’t have <p>to <p>. Try changing your tag <p>to tag <span>.

Hope this helps

+5
source

I know this is old, but the answer is: .x, .x +* { }

ETA: I misunderstood the question. Answer:.x ~ * { }

+4
source

Source: https://habr.com/ru/post/1733231/


All Articles