Home  >  Article  >  Web Front-end  >  How to set line spacing in css

How to set line spacing in css

青灯夜游
青灯夜游Original
2021-05-17 17:17:1719856browse

In CSS, you can set the line spacing through the line height attribute line-height. The syntax format is "line-height: spacing value;". The value of the Line-height attribute can be a relative value, an absolute value or a specific number; the larger the value of line-height, the higher the line spacing.

How to set line spacing in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

There is no attribute that can directly set the line spacing in CSS, so we need to use line-height to set the line spacing. The greater the value of line-height, the higher the line spacing. .

The line-height property is used to set the amount of space used by the line, that is, the distance between lines.

Note: The line-height attribute does not allow negative values.

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

Attribute value:

  • normal Default. Set reasonable line spacing.

  • #number Set a number, which will be multiplied by the current font size to set the line spacing.

  • #length Set a fixed line spacing.

  • % % line spacing based on the current font size.

It can be seen that the value of Line-height is set to a specific numerical value, which can be a relative value or an absolute value. In static pages, the text size is often fixed. Use absolute values, and for forums and blogs where users can customize the font size, they are usually set to relative values, so that the corresponding line spacing can be changed with the user-defined font size.

Example:

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<style type="text/css">
			p.small {
				line-height: 90%
			}
			
			p.big {
				line-height: 200%
			}
		</style>
	</head>

	<body>

		<p>
			这是拥有标准行高的段落。 在大多数浏览器中默认行高大约是 110% 到 120%。 这是拥有标准行高的段落。 这是拥有标准行高的段落。 这是拥有标准行高的段落。 这是拥有标准行高的段落。 这是拥有标准行高的段落。
		</p>

		<p class="small">
			这个段落拥有更小的行高。 这个段落拥有更小的行高。 这个段落拥有更小的行高。 这个段落拥有更小的行高。 这个段落拥有更小的行高。 这个段落拥有更小的行高。 这个段落拥有更小的行高。
		</p>

		<p class="big">
			这个段落拥有更大的行高。 这个段落拥有更大的行高。 这个段落拥有更大的行高。 这个段落拥有更大的行高。 这个段落拥有更大的行高。 这个段落拥有更大的行高。 这个段落拥有更大的行高。
		</p>

	</body>

</html>

How to set line spacing in css

Learning video sharing:css video tutorial

The above is the detailed content of How to set line spacing in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn