Defining a custom font requires the "@font-face" rule of css. The "@font-face" rule is mainly to embed user-defined web fonts into web pages, the syntax is "@font-face{font-family: 'font name';src:url('file address');}".
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
How to make your page support custom fonts, in one sentence, use @font-face.
@font-face is a module in CSS3. It mainly embeds self-defined Web fonts into your web pages. With @font-face## With the emergence of the #module, we are not afraid that we can only use Web-safe fonts when using fonts in Web development. Let’s take a look at how to use @font-face.
First of all, let’s take a look at the grammatical rules of@font-face:
@font-face { font-family: <YourWebFontName>; src: <source> [<format>][,<source> [<format>]]*; [font-weight: <weight>]; [font-style: <style>]; }
Value description
1. YourWebFontName: This value refers to your customized font name. It is best to use the default font you downloaded. It will be referenced to the font-family in your Web element. Such as "font-family:"YourWebFontName";"2. source: This value refers to the storage path of your customized font, which can be a relative path or an absolute path;3. Format: This value refers to the format of your customized font, which is mainly used to help the browser identify it. Its values mainly include the following types: truetype, opentype, truetype-aat, embedded-opentype, avg, etc.; 4. Weight and style: You must be familiar with these two values. Weight defines whether the font is bold, and style mainly defines the font style, such as italics.Compatible browsers
1. TrueTpe (.ttf) format:
.ttf font is the most common for Windows and Mac The font is a RAW format, so it is not optimized for the website. The browsers that support this font are [IE9, Firefox3.5, Chrome4, Safari3, Opera10, iOS Mobile Safari4.2];2. OpenType (.otf) format:
.otf font is considered an original font format, which is built on the basis of TrueType, so it also provides more functions. Browsers that support this font include [Firefox3.5, Chrome4.0, Safari3.1, Opera10.0, iOS Mobile Safari4.2];3. Web Open Font Format(.woff ) Format:
.woff font is the best format among Web fonts. It is an open TrueType/OpenType compressed version. It also supports the separation of metadata packages and supports the browsing of this font. The devices include [IE9, Firefox3.5, Chrome6, Safari3.6, Opera11.1];4. Embedded Open Type (.eot) format:
. eot font is a special font for IE. This format font can be created from TrueType. The browsers that support this font are [IE4];5. SVG (.svg) format:
.svg font is a format based on SVG font rendering. Browsers that support this font include [Chrome4, Safari3.1, Opera10.0, iOS Mobile Safari3.2]. This means that in @font-face we need at least two format fonts, .woff and .eot, and even .svg and other fonts to support more browsing versions. In order to enable @font-face to achieve more browser support,Paul Irish wrote a unique @font-face syntax called Bulletproof @font-face :
@font-face { font-family: 'YourWebFontName'; src: url('YourWebFontName.eot?') format('eot');/*IE*/ src:url('YourWebFontName.woff') format('woff'), url('YourWebFontName.ttf') format('truetype');/*non-IE*/ }But in order to be supported by many browsers, you can also write:
@font-face { font-family: 'YourWebFontName'; src: url('YourWebFontName.eot'); /* IE9 Compat Modes */ src: url('YourWebFontName.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('YourWebFontName.woff') format('woff'), /* Modern Browsers */ url('YourWebFontName.ttf') format('truetype'), /* Safari, Android, iOS */ url('YourWebFontName.svg#YourWebFontName') format('svg'); /* Legacy iOS */ }After talking about so much empty theoretical knowledge, everyone must be a little itchy, so let’s do it first Take a look at how the blue font in the navigation section of the W3CPLUS homepage is implemented. If we have a DOM tag like this, we need to apply a custom font:
HTML Code:
<h2 id="Neues-nbsp-Bauen-nbsp-Demo">Neues Bauen Demo</h2>Define your own Web Font through @font-face:
@font-face { font-family: 'NeuesBauenDemo'; src: url('../fonts/neues_bauen_demo-webfont.eot'); src: url('../fonts/neues_bauen_demo-webfont.eot?#iefix') format('embedded-opentype'), url('../fonts/neues_bauen_demo-webfont.woff') format('woff'), url('../fonts/neues_bauen_demo-webfont.ttf') format('truetype'), url('../fonts/neues_bauen_demo-webfont.svg#NeuesBauenDemo') format('svg'); font-weight: normal; font-style: normal; }I use a relative path here, but of course you can also use an absolute path. At this point we need to apply the defined font to our actual page:
h2.neuesDemo { font-family: 'NeuesBauenDemo' }
Effect:
css video tutorial)
The above is the detailed content of What CSS rules are required to define custom fonts?. For more information, please follow other related articles on the PHP Chinese website!

GoogleDocs在学校和工作环境中变得很流行,因为它提供了文字处理器所期望的所有功能。使用Google文档,您可以创建文档、简历和项目提案,还可以与世界各地的其他用户同时工作。您可能会注意到GoogleDocs不包括MicrosoftWord附带的所有功能,但它提供了自定义文档的能力。使用正确的字体可以改变文档的外观并使其具有吸引力。GoogleDocs提供了大量字体,您可以根据自己的喜好从中选择任何人。如果您希望将自定义字体添加到Google文档,请继续阅读本文。在本文中

在css中,可用list-style-type属性来去掉ul的圆点标记,语法为“ul{list-style-type:none}”;list-style-type属性可设置列表项标记的类型,当值为“none”可不定义标记,也可去除已有标记。

区别是:css是层叠样式表单,是将样式信息与网页内容分离的一种标记语言,主要用来设计网页的样式,还可以对网页各元素进行格式化;xml是可扩展标记语言,是一种数据存储语言,用于使用简单的标记描述数据,将文档分成许多部件并对这些部件加以标识。

在css中,可以利用cursor属性实现鼠标隐藏效果,该属性用于定义鼠标指针放在一个元素边界范围内时所用的光标形状,当属性值设置为none时,就可以实现鼠标隐藏效果,语法为“元素{cursor:none}”。

在css中,rtl是“right-to-left”的缩写,是从右往左的意思,指的是内联内容从右往左依次排布,是direction属性的一个属性值;该属性规定了文本的方向和书写方向,语法为“元素{direction:rtl}”。

转换方法:1、给英文元素添加“text-transform: uppercase;”样式,可将所有的英文字母都变成大写;2、给英文元素添加“text-transform:capitalize;”样式,可将英文文本中每个单词的首字母变为大写。

在css中,可以利用“font-style”属性设置i元素不是斜体样式,该属性用于指定文本的字体样式,当属性值设置为“normal”时,会显示元素的标准字体样式,语法为“i元素{font-style:normal}”。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
