In this lesson you will learn about fonts using CSS. We shall also consider that a particular font is selected for the web- site may be displayed only if the font is installed on the PC, is executed to access the web- site. The description of the following CSS- properties :
font-family
font-style
font-variant
font-weight
font-size
font
Font family [font-family]
Font-family property specifies a prioritized list of font used to display the item, or web- page. If the first font on the list is not installed on the computer from which you access the site, the next font on the list , until it finds the correct one.
Used to categorize fonts two types of names : the name of the family / family-name and common / generic family / generic family. These two terms are explained below .
Family-name
An example of family-name ( often known as "font " ) is , for example , "Arial", "Times New Roman" or "Tahoma".
Generic family
Can best be described as a group of family-names, with uniformed features. Example - sans-serif, sans suite " serif / feet".
The difference can also be illustrated as follows:
Three examples of generic families and some of their family members
When you specify a font for your web- site, you naturally start with the preferred font , followed by some alternative . Recommended in the list with a generic name . Then the page , at least, will be displayed font of the same family if none of the specified fonts .
List of fonts may look like this:
h1 {font-family: arial, verdana, sans-serif;}
h2 {font-family: "Times New Roman", serif;}
Show me an example
Headlines <h1> be displayed using the font "Arial". If it is not installed on the user's machine to be used "Verdana". If both these fonts are not available to show the headlines will be used by the font family sans-serif.
Please note that the name of the font "Times New Roman" contains spaces , so specified in double quotes.
Font Style [font-style]
Font-style property defines normal, italic or oblique. In the example, all the titles will be displayed in italics <h2> italic.
h1 {font-family: arial, verdana, sans-serif;}
h2 {font-family: "Times New Roman", serif; font-style: italic;}
Show me an example
Option font [font-variant]
Font-variant property is used to select between normal or small-caps. Small-caps font uses a small capital letters (upper case) instead of lower case letters . It is not clear ? See the examples :
Four examples of fonts in small caps
If the font-variant is set to small-caps, and small-caps font is not available , the browser will most likely show the text in uppercase .
h1 {font-variant: small-caps;}
h2 {font-variant: normal;}
Show me an example
Weight font [font-weight]
The property font-weight describes how thick or "heavy " a font should be . The font can be normalili bold. Some browsers support even numbers between 100-900 ( in hundreds) to describe the weight of the font.
p {font-family: arial, verdana, sans-serif;}
td {font-family: arial, verdana, sans-serif; font-weight: bold;}
Show me an example
Font size [font-size]
Font size set by the property font-size.
Various units of measurement (for example, pixels and percentages ) to describe the size of the font. In this tutorial, we will use the most common and appropriate units of measurement. Here are some examples :
h1 {font-size: 30px;}
h2 {font-size: 12pt;}
h3 {font-size: 120% ; }
p {font-size: 1em;}
Show me an example
There is one difference in these units : 'px' and 'pt' give the absolute value of the font size , and '%' and 'em' - relative . Many users can not read the small print , for different reasons. To make your web- site accessible to everyone, you have to use relative values, such as ' %' or 'em'.
Here's an illustration of how to set the font size in Mozilla Firefox and Internet Explorer. Try it for yourself - the perfect property , what do you think ?
Shorthand [font]
Using the shorthand font, you can specify all font properties in one single property .
For example, these four lines of text describing the properties for <p>:
p {
font-style: italic;
font-weight: bold;
font-size: 30px;
font-family: arial, sans-serif;
}
Using the shorthand notation , the code can be simplified:
p {
font: italic bold 30px arial, sans-serif;
}
The order of the properties of font is:
font-style | font-variant | font-weight | font-size | font-family