<p>作为一个例子,如果我想让Text1是红色的,但不是Text2:</p>
<pre class="brush:php;toolbar:false;"><div class="red">
Text1
<p class="notred">Text2</p>
</div></pre>
<p>我在css中尝试了这个:</p>
<pre class="brush:php;toolbar:false;">.red :not(.notred) {
color: #ff0000;
}</pre>
<p>尝试这个,它不应用样式Text1或Text2。</p>
<!DOCTYPE html> <html> <style> .red { color: #ff0000; } .notred{ color: #000000; } </style> <body> <div class="red"> Text1 <p class="notred">Text2</p> </div> </body> </html>你可以这样做。