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

คุณสมบัติ font แบบ shorthand สำหรับกำหนดฟอนต์ใน CSS


คุณสมบัติ font (Shorthand)

คุณสมบัติ font ใช้เป็น shorthand เพื่อกำหนดคุณสมบัติฟอนต์หลายอย่างพร้อมกัน เช่น font family, size, style เป็นต้น

ตัวอย่าง

ลองรันโค้ดต่อไปนี้เพื่อเรียนรู้การทำงานของคุณสมบัติ font:

<html>
  <head>
  </head>
  <body>
    <p style="font:italic small-caps bold 13px georgia;">
      Applying all the properties on the text at once. </p>
  </body>
</html>

ลำดับค่าที่บังคับ (จำเป็น):

font: <font-style> <font-variant> <font-weight> <font-size/line-height> <font-family>;
  • font-size และ font-family ต้องมีเสมอ
  • line-height คั่นด้วย slash: 13px/1.5
  • ค่าที่ข้ามไปจะใช้ค่าเริ่มต้น

ตัวอย่าง: font: bold 16px/1.5 "Helvetica Neue", sans-serif;