แบบ อักษรสไตล์คุณสมบัติ
ตัวอย่าง
ตั้งค่าแบบอักษรสำหรับองค์ประกอบ:
document.getElementById("demo").style.font = "italic bold 20px arial,serif";
ความหมายและการใช้งาน
ชุดคุณสมบัติฟอนต์หรือส่งคืนคุณสมบัติฟอนต์แยกกันมากถึงหกคุณสมบัติ ในรูปแบบชวเลข
ด้วยคุณสมบัตินี้ คุณสามารถตั้งค่า/ส่งคืนสิ่งต่อไปนี้ (ตามลำดับนี้):
- รูปแบบตัวอักษร
- แบบอักษรตัวแปร
- ตัวอักษรน้ำหนัก
- ขนาดตัวอักษร
- ความสูงของเส้น
- ตระกูลอักษร
ต้องระบุขนาดแบบอักษรและตระกูลแบบอักษร หากไม่มีค่าอื่นใด ค่าเริ่มต้นจะถูกแทรก หากมี
คุณสมบัติข้างต้นสามารถตั้งค่าด้วยคุณสมบัติสไตล์ที่แยกจากกัน ขอแนะนำให้ใช้คุณสมบัติแยกกันสำหรับผู้เขียนที่ไม่ขั้นสูงเพื่อการควบคุมที่ดีขึ้น
รองรับเบราว์เซอร์
Property | |||||
---|---|---|---|---|---|
font | Yes | Yes | Yes | Yes | Yes |
ไวยากรณ์
ส่งคืนคุณสมบัติฟอนต์:
object.style.font
ตั้งค่าคุณสมบัติแบบอักษร:
object.style.font = "font-style font-variant font-weight font-size/line-height|caption|icon|menu|
message-box|small-caption|status-bar|initial|inherit;"
มูลค่าทรัพย์สิน
Value | Description |
---|---|
style | Sets the font-style |
variant | Sets the text in a small-caps font |
weight | Sets the boldness of the font |
size | Sets the size of the font |
lineHeight | Sets the distance between lines |
family | Sets the font face |
caption | The font used for captioned controls (like buttons, drop-downs, etc.) |
icon | The font used to label icons |
menu | The font used in menus |
message-box | The font used in dialog boxes |
small-caption | The font used in small controls |
status-bar | The font used in window status bars |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
รายละเอียดทางเทคนิค
ค่าเริ่มต้น: | ไม่ระบุ |
---|---|
คืนมูลค่า: | สตริงที่แสดงถึงคุณสมบัติแบบอักษรที่แตกต่างกันขององค์ประกอบ |
เวอร์ชัน CSS | CSS1 |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ส่งคืนแบบอักษรขององค์ประกอบ:
alert(document.getElementById("demo").style.font);
หน้าที่เกี่ยวข้อง
กวดวิชา CSS: แบบอักษร CSS
การอ้างอิง CSS: คุณสมบัติแบบอักษร
❮ สไตล์วัตถุ