Home  >  Article  >  Web Front-end  >  Example analysis of how to retain spaces and line breaks in html pages

Example analysis of how to retain spaces and line breaks in html pages

黄舟
黄舟Original
2017-07-27 14:33:572275browse

We know that when the browser renders and displays the HTML page, it will process the spaces and newlines in the HTML file, so the formatting we originally wrote in the HTML file may not work. The effect, especially when we want to display structured program code, we will encounter problems, as shown below:

<html>

<body>

for i = 1 to 10
     print i
next i

</body>
</html>

Such HTML files will all be printed when displayed on the browser On one line, it looks like this:

for i = 1 to 10 print i next i

In this way, the understanding of the program cannot be clearly seen, so how can it be displayed as written in the HTML file?

e03b848252eb9375d56be284e690e873The preformatted tag plays its role here. This tag mainly processes spaces and blank lines and retains the spaces and blank lines that exist in the HTML file. . After we add this tag, it looks as follows:

<html>

<body>

<pre class="brush:php;toolbar:false">
for i = 1 to 10
     print i
next i

The displayed effect:

for i = 1 to 10
     print i
next i

The above is the detailed content of Example analysis of how to retain spaces and line breaks in html pages. 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