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

การใช้ฟังก์ชัน var() CSS


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

ตัวอย่าง

คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อใช้ฟังก์ชัน var()

<!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>