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

จัดสไตล์รูทเอลิเมนต์ของเอกสารด้วย CSS


Pseudo-class :root

:root เลือกองค์ประกอบรากของเอกสาร (ใน HTML คือ <html>) ใช้กันบ่อยสำหรับกำหนด CSS custom properties (variables)

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
  <style>
    :root {
      background: blue;
      color: white;
    }
  </style>
</head>
<body>
  <h1>Heading</h1>
  <p>This is demo text.</p>
</body>
</html>