Font-family
Here font-family can be seen as a font variable, the name can be very arbitrary, such as a direct dollar sign ‘$‘ , for example:
@font-face { font-family: ' $ '; Src:local ("Microsoft yahei");
At this time, for ordinary HTML elements, you set its font-family property value to ‘$‘ , then its font performance becomes "microsoft ya black" (if There is a local font).
Even Non-internet Explorer can be used to directly use pure space ‘ ‘ , but one thing to note, is to use these strange characters or a space, you must Quote.
Although the variable name can be very arbitrary, but there is a kind of name, not casually set, is the original system has the font name, such as the following code:
@font-face { font-family: ' Microsoft yahei '; Src:local (simsun);}
From then on, "microsoft ya black" font has become "song body". of course, Sometimes we may need this kind of coverage, for example, a new design supervisor, life most like "microsoft ya black", want to change to other fonts, this time we can use this variable overlay to complete the entire site of the font changes EASILY.
Src
srcRepresents a call to a font file, either a local font file (ie9+ support) or an online address (there may be a cross-domain limitation).
This article mainly focuses on the application of local font Files.
Role 1: shorthand for font filenames
Now many websites will use "microsoft Jas black" font, however, "microsoft ya black" name is a bit long:
. Font { font-family: ' Microsoft Yahei ';}
Small hand a shake, perhaps misspelled, but also add the quotation marks, but also add a space, good trouble le. At this point we can make use of the @font face rules simplification, so that it is easy to remember, writing Faster:
@font-face { font-family:yh; Src:local ("Microsoft yahei");
When using the Direct:
. Font { font-family:yh;}
How clean, how refreshing, how comfortable the mood!
srcalso supports multiple local font addresses appearing at the same time, hey, this simplified CSS code is not a font name, but a big wave font name, for example, A website uses a lot of similar font-family property values:
Body { font-family:pingfangsc-regular,helveticaneue-light, ' Helvetica Neue light ', ' Microsoft Yahei ', sans-serif;}. xxxx { font-family:pingfangsc-regular,helveticaneue-light, ' Helvetica Neue light ', ' Microsoft Yahei ', sans-serif;}
Although said, the implementation of the time, with the help of sass, less tools such as the font names have become variables, writing code seems to have no difficulty, but the resulting CSS is actually more verbose, if we go in essence is the variable @font face , is not only the development of simple, the code is simple, The following processing:
@font-face { font-family:base; Src:local ("helveticaneue-light"), local ("Helvetica Neue light"), local ( "pingfang SC"), local ("Microsoft yahei"), Local (sans-serif);}
So we use the font when the Direct:
Body { font-family:base;}. XXXX { font-family:base;}
Look at the semantics and good, the code is simple, practical and convenient, super use of small tricks.
of course, the local local role is more than that.
The industry has a Chinese font processing tool called "spider" that extracts special Chinese fonts used in the page and generates new, smaller, custom Fonts. We can take a step further on this basis, for example:
Some special title designers like to use the "founder of the thick song" this font (has been purchased copyright), but obviously, so handsome fonts, almost few users installed, so the actual development, all through the tool to generate a new compact version of the "founder of the song" font file, and then through src url()The property method chains the font file Outside.
Great solution, but not perfect enough, why? Although there are not many users to install the "founder of the song" font, it does not mean that no user is using it. imagine, If there is a user installed this font, the result you in the page rendering, but also to go outside the chain an additional file address, is not wasted? Waste of traffic, experience is not necessarily good, if the font file load slow, you will see the text "deformation" process, is obviously unfriendly.
We can take advantage of @font face local further improvements in the implementation code and experience in the rules, as Follows:
@font-face { font-family:fzcys; src:local ("fzyasongs-b-gb"), url ("fzcys.woff2"), url ( "fzcys.woff"), url ("fzcys.ttf");}
thus, Those who installed the "founder of the song" font of the user, there is no font file Request. Loading faster, The user experience has risen, but also save the traffic, so the benefits of nothing harm, but also improper use up.
Font-style
Under chrome, @font face rule settings font-style:italic can skew text, but that's not where it works.
@font faceRules font-style and font-weight similar, are used to set the corresponding font style or weight under what font to Use. Because some fonts may have special italics, Note that the italic word, not to let the shape of the text italic, but rather a specially designed italic font, a lot of details will be different from the physical Request. so, when I use the CSS code font-style:italic , it will call the corresponding font, as Follows:
@font-face { font-family: ' I '; font-style:normal; Src:local (' Fzyaoti ');} @font-face { font-family: ' I '; font-style:italic; Src:local (' Fzshuti ');}
Because the special italic word is not easy to find, so I use "founder yao body" and "founder Shu body" instead of making a schematic. The above CSS code I read: the formulation of a font, called ‘I‘ , when the text style is normal, the font expression using "founder Yao body", when the text set up font-style:italic , the font expression as "founder shu body."
well, now suppose you have CSS and HTML like the Following:
. I { font-family:i;}
<p><i class= "i" > class name is i, tag is I</i></p><p><span class= "i" > class name is i, label is Span</span ></p>
What is the final performance?
Because the <i> label is natural font-style:italic , so theoretically, the above line of text is expressed as "founder Shu body", the following behavior "founder Yao body", The final result is how?
When when, fully compliant, as Follows:
Now you should understand what the @font face rules are for font-style .
Font-weight
font-weightAndfont-stylesimilar, but defines the different words to use different fonts, for noon, this is more thanfont-styleThe applicability is much stronger. I have a very representative example here, the Copyright font "han flag black" is very rich in weight, but this font is not like "siyuan blackbody", Natural can be based onfont-weightProperty value to load the corresponding font file, what to do? Very simple, use@font faceThe rules are redefined, such as the following CSS Code:
@font-face { font-family: ' QH '; font-weight:400; Src:local (' Hyqihei 40S ');} @font-face { font-family: ' QH '; font-weight:500; Src:local (' Hyqihei 50S ');} @font-face { font-family: ' QH '; font-weight:600; Src:local (' Hyqihei 60S ');}
Interpretation is, is a brand-new font, called ‘QH‘ , when the word weight font-weight for 400 The time, the use of "chinese flag black 40S" Word weight font, for 500 The time, use "han instrument flag Black 50S" Word weight font, for 600 The time, the use of "chinese flag black 60S" Word Weight Font.
thus, when we apply the following CSS and HTML code:
. hy-40s,.hy-50s,.hy-60s { font-family: ' QH ';}. hy-40s { font-weight:400;}. hy-50s { font-weight:500;}. hy-60s { font-weight:600;}
<ul> <li class= "hy-40s" > Han instrument flag black 40s</li> <li class= "hy-50s" > Chinese flag Black 50s</li> <li class= "hy-60s" > Han instrument flag Black 60s</li></ul>
We can see the effect of the text and the thickness of the patchwork, as Follows:
If used in Web development, will certainly make our interface more delicate, design more exquisite, visual more Enjoyable.