search

Home  >  Q&A  >  body text

Apply CSS styles to all elements except nested elements

<p>As an example, if I want Text1 to be red, but not Text2:</p> <pre class="brush:php;toolbar:false;"><div class="red"> Text1 <p class="notred">Text2</p> </div></pre> <p>I tried this in css:</p> <pre class="brush:php;toolbar:false;">.red :not(.notred) { color: #ff0000; }</pre> <p>Try this, it does not apply styles Text1 or Text2. </p>
P粉865900994P粉865900994527 days ago492

reply all(1)I'll reply

  • P粉574695215

    P粉5746952152023-08-02 12:01:09


    <!DOCTYPE html>
    <html>
    <style>
    .red {
      color: #ff0000;
    }
    .notred{
      color: #000000;
    }
    </style>
    <body>
    
    <div class="red">
    Text1
    <p class="notred">Text2</p>
    </div>
    
    </body>
    </html>


    You can do this.

    reply
    0
  • Cancelreply