CSS line-height 属性

Definition and Usage

The line-height property sets the distance between lines (line height).

Comment:Negative values are not allowed.

Note

This property affects the layout of the line box. When applied to a block-level element, it defines the minimum distance between the baselines within the element, rather than the maximum distance.

The difference between the computed value of line-height and font-size (in CSS known as 'line spacing') is divided in half, and each is added to the top and bottom of a text line content. The smallest box that can contain these contents is the line box.

The original numeric value specifies a scaling factor, and the descendant elements will inherit this scaling factor rather than the computed value.

See Also:

CSS Tutorial:CSS 文本

HTML DOM Reference Manual:lineHeight Property

Example

Set line height in percentage:

p.small {line-height:90%}
p.big {line-height:200%}

Try It Yourself

(More examples can be viewed at the bottom of the page)

CSS Syntax

line-height: normal|number|length|initial|inherit;

Attribute Value

Value Description
normal Default. Set a reasonable line spacing.
number Set a number, which will be multiplied with the current font size to set the line spacing.
length Set fixed line spacing.
% Percentage line spacing based on the current font size.
inherit Ituturing na dapat minana ng line-height property mula sa magulang na elemento ang halaga nito.

Technical Details

Default Value: normal
Inheritance: yes
Version: CSS1
JavaScript Syntax: object.style.lineHeight="2"

TIY Example

Pagtatakda ng letter-spacing gamit ang percent
Ito ay nagpapakita kung paano gamitin ang percent value upang itakda ang letter-spacing sa isang paragrapo.
Pagtatakda ng letter-spacing gamit ang pixel value
Ito ay nagpapakita kung paano gamitin ang pixel value upang itakda ang letter-spacing sa isang paragrapo.
Pagtatakda ng letter-spacing gamit ang numero
Ito ay nagpapakita kung paano gamitin ang isang numero upang itakda ang letter-spacing sa isang paragrapo.

Suporta ng Browser

Ang numero sa talahanayan ay nagtatalaga ng unang bersyon ng browser na ganap na sumusuporta sa katangian na iyon.

Chrome IE / Edge Firefox Safari Opera
1.0 4.0 1.0 1.0 7.0