为什么在任何给定的.html文件中将换行符转换为“'”? [英] Why is a newline converted into a ' ' in any given .html file?

查看:97
本文介绍了为什么在任何给定的.html文件中将换行符转换为“'”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与HTML相关的问题。为了演示我的
简单问题,我将使用一个简单的例子。



考虑以下HTML内容:

 < html> 
Foo:Bar
< / html>

当您在浏览器中调用它时,它会在
中显示Foo:Bar线。到目前为止这样好。



然而,当你做几乎相同,并存储这个:

 < HTML> 
Foo
:Bar
< / html>

换句话说,如果您在':'
字符之前添加换行符,然后突然显示在这里:

 Foo:Bar

现在我想知道从哪里来?因为该字符
不是原始源文件的一部分。

解决方案

在HTML中,回车或换行源代码被视为空白空间并呈现为空间。在呈现的页面上,多个空格或空格(CR,LF,制表符等)等于单个空格。

因此,如果您的50个回车符源代码位于 Foo :Bar 之间,它将呈现一个空格( Foo:Bar )当HTML页面显示在浏览器中时。



从HTML 4.01规范: 控制换行符


I have a question related to HTML. In order to demonstrate my simple question, I will use a minimal example.

Consider the following HTML content:

<html>
Foo: Bar 
</html>

When you call this in a browser, it displays "Foo: Bar" in one line. So far so good.

However had, when you do almost the same, and store this:

<html>
Foo
: Bar 
</html>

In other words, if you add a newline right before the ':' character, then suddenly the display becomes this here:

"Foo : Bar"

Now I wonder where from the ' ' comes? Because that character is not part of the original source.

解决方案

In HTML a carriage return or line feed in the source code is treated as white space and rendered as a space. Multiple spaces or white space (CR, LF, tabs, etc.) amount to a single white space on the rendered page.

So if you have 50 carriage returns in your source code between Foo and : Bar it will render a one space (Foo : Bar) when th HTML page is displayed in the browser.

From the HTML 4.01 spec: Controlling line breaks.

这篇关于为什么在任何给定的.html文件中将换行符转换为“'”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆