Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css select all descendants (asterisk) of elements with a class

Tags:

css

selector

I want to select all descendant elements of the element with class="x" this way:

<!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 those elements. neither *.x * does.

what am i doing wrong?

like image 586
mykhal Avatar asked Dec 01 '25 01:12

mykhal


1 Answers

You can't have a <p> in a <p>. Try changing your inner <p> tag to a <span> tag.

Hope this helps

like image 193
mattbasta Avatar answered Dec 03 '25 17:12

mattbasta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!