Whitespace processing in HTML/CSS and how to preserve whitespace in the page

Whitespace processing in HTML/CSS and how to preserve whitespace in the page

Whitespace rules in HTML

In HTML, multiple spaces in the content are generally regarded as one, and consecutive spaces 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 browser processing also applies to tabs (\t) and line breaks (\r and \n) in addition to the normal space key, which can be explicitly indicated by using tags.

HTML whitespace preservation

At this time, if you want multiple consecutive spaces in HTML to be displayed on the web page, the browser will show the real space indentation and line break effects. We know that there are generally two ways, using tabs, or using to represent spaces. as follows:

<pre> fly63 com </pre>

or

&nbsp;fly63&nbsp;&nbsp;&nbsp;com&nbsp;

The spaces in Html are currently: | | | |

&nbsp; &#160; Non-breaking whitespace (1 character width)
&ensp; &#8194; Half space (1 character width)
&emsp; &#8195; A space (2 characters wide)
&thinsp; &#8201; Narrow whitespace (less than 1 character width)

SS space reserved

1. In CSS, when the white-space property value is pre, it is processed in the same way as the tag. The browser will preserve 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 CSS white-space property is pre-line, it means retaining line breaks. Except that line breaks are output as 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

3. The CSS letter-spacing property is used to set the spacing between characters in the text, for example:

<p style="letter-spacing:5px;">Welcome! </p>

The display effect is: Welcome!

4. The word-spacing property of CSS is used to set the spacing between words in the text, for example:

<p style="word-spacing:5px">Happy new year!</p>

The display effect is: Happy new year!

Summarize

This is the end of this article about space processing in HTML/CSS and how to retain spaces in the page. For more relevant html css space processing content, please search 123WORDPRESS.COM's previous articles or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  How to optimize a website to increase access speed update

>>:  CentOS 7.9 installation and configuration process of zabbix5.0.14

Recommend

Explain TypeScript mapped types and better literal type inference

Table of contents Overview Using mapped types to ...

Detailed explanation of sql_mode mode example in MySQL

This article describes the sql_mode mode in MySQL...

A Brief Analysis on the Time Carrying Problem of MySQL

The default time type (datetime and timestamp) in...

Detailed explanation of CSS image splicing technology (sprite image)

CSS image splicing technology 1. Image stitching ...

Mysql transaction isolation level principle example analysis

introduction You must have encountered this in an...

Solve the problem of MySql8.0 checking transaction isolation level error

Table of contents MySql8.0 View transaction isola...

Implementation principle and configuration of MySql master-slave replication

Database read-write separation is an essential an...

Detailed Introduction to MySQL Innodb Index Mechanism

1. What is an index? An index is a data structure...

Linux sar command usage and code example analysis

1. CPU utilization sar -p (view all day) sar -u 1...

Do you know the weird things in Javascript?

Our veteran predecessors have written countless c...

How to implement animation transition effect on the front end

Table of contents Introduction Traditional transi...

Getting Started Tutorial for Beginners: Domain Name Resolution and Binding

So after registering a domain name and purchasing...

mySql SQL query operation on statistical quantity

I won't say much nonsense, let's just loo...

How to change the dot in the WeChat applet swiper-dot into a slider

Table of contents background Target Effect Ideas ...

How to use docker to build redis master-slave

1. Build a Docker environment 1. Create a Dockerf...