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

คุณสมบัติ CSS all - รีเซ็ตคุณสมบัติทั้งหมด

ใช้คุณสมบัติ all เพื่อรีเซ็ตคุณสมบัติ CSS ทั้งหมดของ element ให้กลับสู่ค่าเริ่มต้น สามารถตั้งค่าเป็น initial, inherit หรือ unset ได้

ตัวอย่างโค้ด

<!DOCTYPE html> <html>    <head>       <style>          html {             color: blue;          }          #demo {             background-color: yellow;             color: red;             all: inherit;          }          </style>    </head>    <body>       <h2>CSS all property</h2>       <div id = "demo">This is demo text.</div>    </body> </html>

คำอธิบาย

คุณสมบัติ all เป็น shorthand ที่รวมคุณสมบัติ CSS ทั้งหมด (ยกเว้น unicode-bidi และ direction) การตั้งค่า all: inherit จะทำให้ element #demo สืบทอดคุณสมบัติทั้งหมดจาก parent (html) ทำให้สีตัวอักษรเป็นสีน้ำเงินตามที่กำหนดใน html แทนที่จะเป็นสีแดง

ค่าที่ใช้ได้:

  • initial - คืนค่าเริ่มต้นของแต่ละคุณสมบัติ
  • inherit - สืบทอดจาก parent element
  • unset - ใช้ inherit ถ้าสืบทอดได้ ไม่งั้นใช้ initial
  • revert - คืนค่า user-agent stylesheet (เพิ่มใน CSS Cascading and Inheritance Level 4)