当前位置:网站首页>Dtcloud uses custom fonts
Dtcloud uses custom fonts
2022-07-24 13:19:00 【Jiang Zhenjian 15954039008】
dtcloud Support the use of custom fonts , To get rid of the limitation of default fonts :
@font-face
@font-face CSS at-rule Specify a custom font for displaying text ; Fonts can be loaded from remote servers or locally installed fonts . If provided local() function , Find the specified font name from the user's local , And found a match , Local fonts will be used . otherwise , The font will use url() Function download resources .
By allowing authors to provide their own Fonts ,@font-face Make design content possible , At the same time, it will not be called " The Internet - Security " Font restrictions ( Fonts are so common that they can be widely used ). Specifying the search and use of locally installed font names can make fonts more customizable than basic fonts , At the same time, this function can be realized without relying on the network .
Use... At the same time url() and local() When the function , Copies of fonts that have been installed for the user are used when they need to be used , If you don't find a copy of the font locally, you will go to the copy you downloaded to find the font .
@font-face Rules are not only used in CSS The top floor of , It can also be used in any CSS In the condition group rule .
@font-face {
font-family: "Open Sans";
src: url("/fonts/OpenSans-Regular-webfont.woff2") format("woff2"),
url("/fonts/OpenSans-Regular-webfont.woff") format("woff");
}
summary
This one is called @font-face Of CSS @ The rules , It allows web developers to specify online fonts for their web pages . In this way, the author prepared his own typeface ,@font-face It can eliminate the dependence on the user's computer font . @font-face Not only can it be placed in CSS Top of , It can also be placed in @ The rules Of Condition rule group in .
grammar
@font-face {
[ font-family: <family-name>; ] ||
[ src: <src>; ] ||
[ unicode-range: <unicode-range>; ] ||
[ font-variant: <font-variant>; ] ||
[ font-feature-settings: <font-feature-settings>; ] ||
[ font-variation-settings: <font-variation-settings>; ] ||
[ font-stretch: <font-stretch>; ] ||
[ font-weight: <font-weight>; ] ||
[ font-style: <font-style>; ] ||
[ size-adjust: <size-adjust>; ] ||
[ ascent-override: <ascent-override>; ] ||
[ descent-override: <descent-override>; ] ||
[ line-gap-override: <line-gap-override>; ]
}
where
<family-name> = <string> | <custom-ident>+
Value
font-family
The specified font name will be used for font or font-family attribute ( i.e. font-family: ; )
src
The location of the remote font file URL Or the font name on the user's computer , have access to local Syntax specifies the font on the user's local computer by name ( i.e. src: local(‘Arial’); ). If the font cannot be found , Will try other sources , Until you find it .
font-variant (en-US)
A font-variant value.
font-stretch (en-US)
A font-stretch value.
font-weight (en-US)
A font-weight value.
font-style
about src Description of the indicated font . If the required font matches the description , Use this font-face Defined font .
unicode-range (en-US)
In the @font-face As defined in unicode Font range
Example
The following example simply defines a downloadable font , And applied to the whole document body On the label .
View live sample
<html>
<head>
<title>Web Font Sample</title>
<style type="text/css" media="screen, print">
@font-face {
font-family: "Bitstream Vera Serif Bold";
src: url("https://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");
}
body {
font-family: "Bitstream Vera Serif Bold", serif }
</style>
</head>
<body>
This is Bitstream Vera Serif Bold.
</body>
</html>
In the next example , The user's local font is used "Helvetica Neue Bold" Backup of ; If the current user ( browser ) The font is not installed ( Both possible font names have been tried ), Will use the downloaded font "MgOpenModernaBold.ttf" Instead of :
@font-face {
font-family: MyHelvetica;
src: local("Helvetica Neue Bold"),
local("HelveticaNeue-Bold"),
url(MgOpenModernaBold.ttf);
font-weight: bold;
}
The following example has been deleted from the original English .
This example defines a new font , Words of normal thickness are in fonts Times New Roman, Bold characters are Consolas.
@font-face {
font-family: myFirstFont;
src: local("Times New Roman");
font-weight:normal;
}
@font-face {
font-family: myFirstFont;
src: local(Consolas);
font-weight:bold;
}
Be careful
the Web fonts Still limited by the same domain ( The font file must be in the same domain as the web page calling it ), But you can use HTTP access controls Lift this restriction .
Because there is no for TrueType(ttf), OpenType(otf) and Web Open File Format(WOFF) Font definition MIME, Therefore, you cannot set specific for these font types MIME( actually WOFF Of MIME Will be application/font-woff, But browsers don't know about this MIME The identification of is not uniform , Other fonts are similar , Can be used temporarily application/octet-stream).
You can't be in a CSS Define... In the selector @font-face . for example , This is not valid :
.className {
@font-face {
font-family: MyHelvetica;
src: local("Helvetica Neue Bold"), local("HelveticaNeue-Bold"),
url(MgOpenModernaBold.ttf);
font-weight: bold;
}
}
边栏推荐
- Prototype inheritance
- The MySQL select delay scenario corresponds to that all database query statements will be delayed. After the scenario injection, I executed one
- An example of how to save various data types by using esp32 EEPROM library functions under Arduino framework
- Writing browser plug-ins
- I realize large top stack with C I
- Windivert: capture and modify packages
- About thread (3) thread synchronization
- Embedded problem troubleshooting methods, network problems, SD card problems, device startup problems, serial port problems, I2C problems, SPI problems, PCIe problems, etc
- Custom scroll bar
- binary search
猜你喜欢

How to draw Bezier curve and spline curve?

【C语言】详细的文件操作相关知识

Sorting method: bubble sorting (use an array to arrange a string of numbers in order (from large to small or from small to large))

Go deadlock problem

vscode配置用户代码片段(包括删除方法)

About thread (4) thread interaction

27. Longest increasing subsequence

Inversion of array (output in reverse order) (define an array and assign a value to output the array in reverse order)

从云原生到智能化,深度解读行业首个「视频直播技术最佳实践图谱」

登临科技联合创始人王平:创新+自研“双核”驱动,GPU+赋能AI落地生根|量子位·视点分享回顾...
随机推荐
regular
Finclip's "applet export app" function has been updated again by the company
Voice recognition based on MATLAB
Sorting method: bubble sorting (use an array to arrange a string of numbers in order (from large to small or from small to large))
2022.07.21
30. Rearrange the linked list
关于如何提升TTL(UART)通信抗干扰——心得
【C语言】动态内存管理
I 用c I 实现 大顶堆
[stm32] internal independent watchdog iwdg
如何用WebGPU流畅渲染百万级2D物体?
Go deadlock problem
Relevant laws of animation movement (judge where to move according to parameters)
About thread (5) thread pool
AtCoder Beginner Contest 261 F // 树状数组
Speech processing based on MATLAB
20201127 use markdown to draw UML diagrams, graphviz installation experience hematemesis finishing
CMake基本语法(一)
Arduino框架下ESP32 EEPROM库函数实现对各数据类型保存示例
class