Recently, many people have mentioned how to select fonts on webpages. Although the problem is small, it is basic in front-end development, because the current webpage is still dominated by text information, and the font, as one of the most important parameters of text representation, naturally, it has a very important position. Hihi, everybody ~ Recently, many people have mentioned how to select fonts on webpages. Although the problem is small, it is basic in front-end development, because the current webpage is still dominated by text information, and the font, as one of the most important parameters of text representation, naturally, it has a very important position. Unfortunately, the importance of fonts has not been paid enough attention for a long time. Many people still stick to the font-family: "", Arial, Helvetica, and serif phases, but do not understand why the settings are reasonable. Now let me talk about the ins and outs of fonts.
-Font-family
We know that the font-family rule is used to define fonts in CSS rules. After carefully reviewing the CSS documents, we did not find any rules that can specify a specific font.
Think about the code that you saw around the world 10 years ago:
< Font Face = "Frankin Gothic Book" > Lorem Ipsum Font>
Almost no one will consider that Frankin Gothic Book is a Windows only font. The font of Frankin Gothic Book is invisible on a Mac. The default font of Mac is used because the font cannot be found. As a result, the style of the webpage is completely different from that of the original one, and it cannot achieve the effect of Frankin Gothic Book. So W3C proposed the concept of font set-to form a list of similar fonts in order of priority. The browser matches the list header and finds the first available font, and use this font to display.
For example, in the above example, we can create such a font set:
<SpanStyle= 'Font-family: "Franklin Gothic Book", "Lucida Grande "'>Lorem Ipsum Span>
-
Let's see how the browser displays this text:
-
- In Windows: the browser starts searching from the first font in the list. The system contains the Frankin Gothic Book, which is displayed in the Frankin Gothic Book font.
- Mac: the browser starts searching from the first font in the list-the Frankin Gothic Book does not exist in the system, and the search fails. Continue to search for the next font, Lucida Grande. The Lucida Grande font exists in the system. The search is terminated and displayed in the Lucida Grande font.
In this way, Mac can display the text in a Lucida Grande font similar to Frankin Gothic Book.
However, there may be a computer with no Frankin Gothic Book or Lucida Grande font on it, so it still cannot display the text above correctly. As a result, developers had to constantly Add fonts in the font list to adapt to various systems, resulting in the loss of the original "organization approximate font" function. Therefore, the font set introduces the "generic font family", that is, the serif and sans-serif we often see. I will introduce these two in detail in future articles, as well as some other general font families. Here, we can simply think of them as "a final alternative font specified by the browser when all specified fonts fail ".
For example, we are improving the example text above:
<SpanStyle= 'Font-family:"Franklin Gothic Book", "Lucida Grande", sans-serif'>Lorem Ipsum Span>
-
Let's see how the browser displays the improved text:
-
- In Windows: the browser starts searching from the first font in the list. The system contains the Frankin Gothic Book, which is displayed in the Frankin Gothic Book font.
- Mac: the browser starts searching from the first font in the list-the Frankin Gothic Book does not exist in the system, and the search fails. Continue to search for the next font, Lucida Grande. The Lucida Grande font exists in the system. The search is terminated and displayed in the Lucida Grande font.
- A system: the browser starts searching from the first font in the list. The system does not contain the Frankin Gothic Book, and the search fails. Continue to search for the next font-The Lucida Grande Font does not exist in the system. Continue to search for the next font-General font sans-serif. The browser uses its default sans-serif font "Arial" to display this text.
Pay attention to two points. First, the font corresponding to the generic font family is determined by the browser. In the preceding example, the browser specifies Arial as the sans-serif font, but it is entirely possible that another browser specifies Helvetica as its sans-serif font. The specific font cannot be used as expected. Secondly, the general font family is only a substitute scheme in which other fonts in the font set are ineffective. So --Designers should give as many font sets as possible to cover all systems as much as possible, instead of relying on the generic font family..
Either of the following statements is incorrect:
<SpanStyle= "Font-family: sans-serif">Lorem Ipsum Span>
<SpanStyle= "Font-family: sans-serif, Arial">Lorem Ipsum Span>
The first mistake in writing is that it is equivalent to having no font specified at all and is still handed over to the browser to select the font. Writing is equivalent to not writing.
The second mistake lies in order. Because the generic font family should work only when all other fonts in a font set expire. Therefore, placing the specified font after the General font will cause the General font to be used if the specified font has not been matched. Therefore, make sure that the general font is placed at the last position in the font set.
In addition, two things are described here.
First, although the browser uses the font set font rules, they seem very simple, but they are actually very trickish. I will explain it in a later article.
Secondly, although the font CSS rule name is font-family, it is essentially a font set, not a printed font family. Printed font family refers to a series of different combinations of the same words, such as Lucida Family (including Lucida Sans, Lucida Sans Typewriter, Lucida Console, Lucida Grande, etc.) and Arial Family (Arial, arial Black, Arial Rounded MT, etc.), but obviously these font families are not suitable for use directly as a font set.
Today, we are here. Next, let's take a closer look at the general font family.