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

ตัวแปรใน CSS


ตัวแปรใน CSS ใช้เพื่อเพิ่มค่าคุณสมบัติที่กำหนดเองให้กับหน้าเว็บของคุณ ตั้งชื่อที่กำหนดเองของคุณสมบัติและตั้งค่าให้กับมัน

คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อใช้ตัวแปรใน CSS เพื่อเปลี่ยนสีพื้นหลังและข้อความ

ตัวอย่าง

<!DOCTYPE html>
<html>
   <head>
      <style>
         :root {
            --my-bg-color: blue;
            --my-color: white;
         }
         #demo {
            background-color: var(--my-bg-color);
            color: var(--my-color);
         }
      </style>
   </head>
   <body>
      <h1>Heading One</h1>
      <div id = "demo">This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text.
      </div>
      <br>
   </body>
</html>