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

黄舟
Release: 2017-07-27 14:33:57
Original
2235 people have browsed it

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>
Copy after login

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
Copy after login

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

The 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: </span></p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:html;toolbar:false;"><html>

<body>

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

The displayed effect:

for i = 1 to 10
     print i
next i
Copy after login

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!

Related labels:
source:php.cn
Previous article:Solution to the space occupied by line breaks in HTML Next article:Detailed explanation of how to set the default selected options for the