Home >Web Front-end >HTML Tutorial >How to keep spaces in text in html

How to keep spaces in text in html

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-06-04 16:39:197438browse

In HTML, you can use the white-space attribute to retain spaces in the text. You only need to set the "white-space:pre|pre-line" style in the element. The white-space attribute declares how to handle whitespace characters in elements during the layout process.

How to keep spaces in text in html

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

Rules for spaces in html

Multiple spaces in content in html are generally regarded as one, and multiple consecutive space characters are automatically merged. At the same time, the spaces before and after the content will also be cleared, as follows:

<p> fly63   com </p> 

The display effect is:

fly63 com 

Note: This mechanism of the browser is also applicable to other than ordinary space keys. Including tab characters (\t) and newline characters (\r and \n), line breaks can be explicitly represented by using the 0c6dc11e160d3b678d68754cc175188a tag. The white-space attribute sets how whitespace within an element is handled.

This attribute declares how to handle whitespace characters in elements during the layout process. The values ​​pre-wrap and pre-line are new in CSS 2.1.

1. In CSS, when the value of the white-space attribute is pre, it will be processed in the same way as the e03b848252eb9375d56be284e690e873 tag. The browser will retain the spaces and line breaks in the text. For example:

<p style="white-space:pre"> fly63  com <p>

The display effect is: ' fly63 com '

2. When the white-space attribute of css is pre-line, it means Line breaks are preserved. Except for the newline character, which will be output as it is, everything else is consistent with the white-space:normal rule.

<p style="white-space: pre-line">
	fly63
	com
</p>

The display effect is:

'fly63

com'

Recommended learning:

html video tutorial

The above is the detailed content of How to keep spaces in text in html. 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