5. CSS Font size and style

Source: Internet
Author: User
Tags italic font

All CSS Font properties:

Font sets all of the fonts properties in a declaration

font-family font family for specified text

Font-size the font size of the specified text

Font-style the font style of the specified text

Font-variant display text in a small uppercase font or in a normal font

Font-weight Specifies the weight of the font.

In CSS, there are two types of font family names:

1. Universal font Family-a combination of font systems with similar appearance (e.g. "Serif" or "monospace")
2. Specific font family-a specific font family (such as "Times" or "Courier")


The Font-family property sets the font family for the text.

The Font-family property should set several font names as a "fallback" mechanism, and if the browser does not support the first font, he will try the next font.

Note: If the name of the font family is more than one word, it must be in quotation marks, such as font Family: "Arial".
Multiple font families are separated by a comma to indicate--->

<HTML><Head><MetaCharSet= "Utf-8"> <title>Beginner's Tutorial (runoob.com)</title><style>P.serif{font-family:"Times New Roman", Times,serif;}P.sansserif{font-family:Arial,helvetica,sans-serif;}</style></Head><Body><H1>CSS font-family</H1><Pclass= "Serif">The font for this paragraph is times New Roman</P><Pclass= "Sansserif">The font for this paragraph is Arial.</P></Body></HTML>

Font style properties for specifying italic text
This property has a value of three:

1. Normal-Normal display text
2. Italic-text displayed in italic font
3. Italic text-The text leans sideways (very similar to italic, but not very supportive)

Example--->

{Font-style:normal;}  {font-style:italic;}  {font-style:oblique;}


The Font-size property sets the size of the text

The ability to manage the size of text is very important in web design. However, you can't make a paragraph look like a caption by resizing the font, or make the title look like a paragraph

The value of the font size can be either absolute or relative size.

Absolute size:

1. Set a specified size text
2. Do not allow users to change text size in all browsers
3. Absolute size is useful when the physical size of the output is determined

Relative size:

1, relative to the surrounding elements to set the size
2. Allow the user to change the text size in the browser

Tip: If you don't specify a font size, the default size is 16 pixels (16px=1em), just like normal text paragraphs

Sets the size of text and pixels, giving you complete control over the text size--->

{font-size:40px;}  {font-size:30px;}  {font-size:14px;}

Use EM to set the font size:

To avoid problems with text that cannot be adjusted in Internet Explorer, many developers use EM units instead of pixels.

EM size units are recommended by the consortium.

1em is equal to the current font size. The default text size in the browser is 16px, so the default size for 1em is 16px. You can convert pixels to em:px/16=em by the following formula

Example--->

{font-size:2.5em/**/{font-size:1.875em /*  */{font-size:0.875em*/* * 

If you use EM units, you can adjust the text size in all browsers. Unfortunately, it's still an Internet Explorer problem. When you resize text, it is larger or smaller than the normal size

In the solution for all browsers, the default font size for the <body> element is set as a percentage.
Using percentages and EM combinations--->

{font-size:100%;}  {font-size:2.5em;}  {font-size:1.875em;}  {font-size:0.875em;}

5. CSS Font size and style

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.