Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

จัดสไตล์ Element ที่ไม่ใช่ Element ที่ระบุด้วย :not() Selector

ใช้ :not(selector) เพื่อจัดสไตล์ Element ทุกตัว ยกเว้น Selector ที่ระบุ

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
    <style>
        p {
            color: red;
        }
        :not(p) {
            color: blue;
        }
    </style>
</head>
<body>
    <h1>Heading 1</h1>
    <h2>Heading 2</h2>
    <h3>Heading 3</h3>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
</body>
</html>

ผลลัพธ์: <p> สีแดง ส่วน <h1>, <h2>, <h3> สีน้ำเงิน

การใช้งานขั้นสูง: :not(.class), :not(#id), :not(:first-child) เป็นต้น