CSS @ font-face Rule
مثال
حدد خطًا يسمى "myFirstFont" ، وحدد عنوان URL حيث يمكن العثور عليه:
@font-face
{
font-family: myFirstFont;
src: url(sansation_light.woff);
}
المزيد من الأمثلة "جربها بنفسك" أدناه.
التعريف والاستخدام
مع هذه @font-face
القاعدة ، لم يعد على مصممي الويب استخدام أحد الخطوط "الآمنة للويب" بعد الآن.
في @font-face
القاعدة ، يجب أولاً تحديد اسم للخط (مثل myFirstFont) ، ثم الإشارة إلى ملف الخط.
لاستخدام الخط لعنصر HTML ، ارجع إلى اسم الخط (myFirstFont) من خلال خاصية font-family:
div
{
font-family: myFirstFont;
}
دعم المتصفح
القاعدة @font-face
مدعومة في Edge و Chrome و Firefox و Safari و Opera.
تحدد الأرقام الواردة في الجدول إصدار المستعرض الأول الذي يدعم تنسيق الخط بشكل كامل.
Font format | |||||
---|---|---|---|---|---|
TTF/OTF | 9.0* | 4.0 | 3.5 | 3.1 | 10.0 |
WOFF | 9.0 | 5.0 | 3.6 | 5.1 | 11.1 |
WOFF2 | 14.0 | 36.0 | 39.0 | 10.0 | 26.0 |
SVG | Not supported | Not supported | Not supported | 3.2 | Not supported |
EOT | 6.0 | Not supported | Not supported | Not supported | Not supported |
* لا يعمل تنسيق الخط إلا عند تعيينه ليكون "قابلاً للتثبيت".
بناء الجملة
@font-face
{
font-properties
}
Font descriptor | Values | Description |
---|---|---|
font-family | name | Required. Defines the name of the font. |
src | URL | Required. Defines the URL(s) where the font should be downloaded from |
font-stretch | normal condensed ultra-condensed extra-condensed semi-condensed expanded semi-expanded extra-expanded ultra-expanded |
Optional. Defines how the font should be stretched. Default value is "normal" |
font-style | normal italic oblique |
Optional. Defines how the font should be styled. Default value is "normal" |
font-weight | normal bold 100 200 300 400 500 600 700 800 900 |
Optional. Defines the boldness of the font. Default value is "normal" |
unicode-range | unicode-range | Optional. Defines the range of unicode characters the font supports. Default value is "U+0-10FFFF" |
مزيد من الأمثلة
مثال
يجب إضافة قاعدة @ font-face أخرى تحتوي على واصفات للنص الغامق:
@font-face {
font-family: myFirstFont;
src: url(sansation_bold.woff);
font-weight: bold;
}
الملف "sansation_bold.woff" هو ملف خط آخر ، يحتوي على الأحرف الغامقة لخط Sansation.
ستستخدم المتصفحات هذا كلما تم عرض جزء من النص مع مجموعة الخطوط "myFirstFont" بالخط العريض.
بهذه الطريقة يمكنك الحصول على العديد من قواعد @ font-face للخط نفسه.
الصفحات ذات الصلة
برنامج CSS التعليمي: CSS Web Fonts