คำสั่ง font-face
คำสั่ง @font-face อนุญาตให้กำหนด
ฟอนต์แบบกำหนดเอง โดยที่ต้นฉบับ
ถูกเก็บไว้ในไฟล์ ฟอนต์นี้สามารถ
เชื่อมต่อได้ในภายหลังโดยใช้คุณสมบัติ font-family
ไวยากรณ์
@font-face {
ชื่อฟอนต์;
แหล่งที่มาสำหรับค้นหาฟอนต์;
}
ตัวอย่าง
มาลองหาฟอนต์บนคอมพิวเตอร์ท้องถิ่นของเรา:
<body>
This is Montserrat SemiBold.
</body>
@font-face {
font-family: "Montserrat SemiBold";
src: local("Montserrat SemiBold");
}
body {
font-family: "Montserrat SemiBold";
}
#elem {
animation: anim 3s infinite;
border: 1px solid black;
width: 50px;
height: 50px;
}
:
ตัวอย่าง
และตอนนี้ให้ระบุที่อยู่ของเซิร์ฟเวอร์ระยะไกล สำหรับการค้นหาฟอนต์:
<body>
This is Bitstream Vera Serif Bold.
</body>
@font-face {
font-family: "Bitstream Vera Serif Bold";
src: url("https://mdn.github.io/css-examples/web-fonts/VeraSeBd.ttf");
}
body {
font-family: "Bitstream Vera Serif Bold", serif;
}
#elem {
animation: anim 3s infinite;
border: 1px solid black;
width: 50px;
height: 50px;
}
: