导出 (0) 打印
全部展开
EN
此内容没有您的语言版本,但有英语版本。

font-size property

Specifies a value that indicates the font size used for text in the object.

Syntax

font-size: <absolute-size> | <relative-size> | <length> | <percentage>

Property values

absolute-size

Set of keywords that indicate predefined font sizes. Named font sizes scale according to the user's font setting preferences. Possible values include the following: xx-small, x-small, small, medium, large, x-large, xx-large.

relative-size

Set of keywords that are interpreted as relative to the font size of the parent object. Possible values include the following: smaller, larger.

length

Floating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px). For more information about the supported length units, see the CSS Values and Units Reference.

percentage

Floating-point number, followed by a percent (%). The value is a percentage of the parent object's font size.

CSS information

Applies ToAll elements
Mediavisual
Inherited1
Initial Valuemedium

Remarks

Negative values are not allowed. Font sizes using the proportional "em" measure are based on the font size of the parent object.

As of Microsoft Internet Explorer 6, when you use the !DOCTYPE declaration to specify standards-compliant mode, the default value for this property is medium, not small.

Possible length values specified in a relative measurement, using the height of the element's font (em) or the height of the letter "x" (ex), are supported in Microsoft Internet Explorer 4.0 and later.

Examples

This example sets the default font size for the document body, and then creates and applies CSS styles to change the font size.


body {
   font-size: 10pt;
}
.absolute {
   font-size: medium;
}
.relative {
   font-size: large;
}
.length {
   font-size: 14pt;
}
.percentage {
   font-size: 150%;
}


<body>
  <p>Lorem ipsum dolor sit amet... (<em>font-size: 10pt</em>)</p>
  <p class="absolute">Lorem ipsum dolor sit amet... (<em>font-size: medium</em>)</p>
  <p class="relative">Lorem ipsum dolor sit amet... (<em>font-size: large</em>)</p>
  <p class="length">Lorem ipsum dolor sit amet... (<em>font-size: 14pt</em>)</p>
  <p class="percentage">Lorem ipsum dolor sit amet... (<em>font-size: 150%</em>)</p>
</body>

The following image shows the result. The first line of text shows the default body element font size. The second line of text shows an absolute-size font-size setting. The third line of text shows a relative-size font-size setting. The fourth line of text shows a length font-size setting. The final line of text shows a percentage font-size setting:

An image showing text with different font-size attribute settings.

See also

CSSStyleDeclaration
currentStyle
defaults
runtimeStyle
style
Reference
font
Conceptual
CSS Values and Units Reference

 

 

显示:
© 2014 Microsoft