白色空间,标签中的新行 [英] White space, new lines in tags

查看:66
本文介绍了白色空间,标签中的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么规则处理带有尾随空格的属性值,或带有嵌入换行符的标签或

属性值?示例如下:HREF带有

嵌入式换行符,SRC带有尾随空格,IMG标签分布在

多行。


< a href ="我自己

">

< img src =" /images/picture.gif" width =" 80"

height =" 65"

alt ="什么,我担心?">< / a>

解决方案

Harlan Messinger写道:

什么规则处理属性值与尾随空格或标签或
具有嵌入换行符的属性值?示例如下:带有嵌入式换行符的HREF,带有尾随空格的SRC,以及遍布多行的IMG标记。

< a href =" myself.html
">
< img src =" /images/picture.gif" width =" 80"
height =" 65"
alt ="什么,我担心?">< / a>




属性之间的空白区域(包括换行符)并不重要,

尽可能多地使用它 - 我经常使用它来保持线条简短。


关于属性值中的空格:HTML规范说

用户代理可能会忽略CDATA

属性值中的前导和尾随空格。

< http://www.w3.org/TR/REC-html40/types.html#h-6.2>

我没有详细测试过这个,但我认为最多浏览器确实剥离了

的空白区域 - 我已经看到各种网站都有这样的链接,似乎

工作。但你不应该依赖它,一些UA可能不会这样做并且遇到一个

断开的链接。


-

Benjamin Niemann

电子邮件:粉红色at odahoda dot de

WWW: http://pink.odahoda.de/


Harlan Messinger写道:

什么规则处理属性具有尾随空格的值,或具有嵌入换行符的标签或
属性值?示例如下:带有嵌入式换行符的HREF,带有尾随空格的SRC,以及遍布多行的IMG标记。

< a href =" myself.html
">
< img src =" /images/picture.gif" width =" 80"
height =" 65"
alt ="什么,我担心?">< / a>




< span id = foo onclick =" alert(''不要\

忘记& nbsp;包含&#x5C;

这个'')">点击我< / span>


来自维也纳的Csaba Gabor


< blockquote>

Harlan Messinger写道:

什么规则处理带有尾随空格的属性值,或带有嵌入换行符的标签或
属性值?示例如下:带有嵌入式换行符的HREF,带有尾随空格的SRC,以及遍布多行的IMG标记。

< a href =" myself.html
">
< img src =" /images/picture.gif" width =" 80"
height =" 65"
alt ="什么,我担心?">< / a>




空格字符(空格,制表符,换页符,新行)并不重要

并由解析器折叠到单个空格(除非在< pre>

block)。


这是所有UA(包括Amaya)的HTML规则。


你可能想看相反,在* tag

之间的换行符和空格*因为在某些不同的实现中它会导致

DOM树中的幻象节点。


What rules deal with attribute values with trailing spaces, or tags or
attribute values with embedded newlines? Examples below: the HREF with
embedded newline, the SRC with trailing spaces, and IMG tag spread over
multiple lines.

<a href="myself.html
">
<img src="/images/picture.gif " width="80"
height="65"
alt="What, me worry?"></a>

解决方案

Harlan Messinger wrote:

What rules deal with attribute values with trailing spaces, or tags or
attribute values with embedded newlines? Examples below: the HREF with
embedded newline, the SRC with trailing spaces, and IMG tag spread over
multiple lines.

<a href="myself.html
">
<img src="/images/picture.gif " width="80"
height="65"
alt="What, me worry?"></a>



White space (including linebreaks) between attributes is not significant,
use it as much as you like - I use this often to keep lines short.

Regarding white space in attribute values: the HTML Spec says
User agents may ignore leading and trailing white space in CDATA
attribute values.
<http://www.w3.org/TR/REC-html40/types.html#h-6.2>
I have not tested this in detail, but I think that most browsers do strip
the white space - I have seen various sites with such links and it seems to
work. But you should not rely on it, some UAs may not do it and encounter a
broken link.

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/


Harlan Messinger wrote:

What rules deal with attribute values with trailing spaces, or tags or
attribute values with embedded newlines? Examples below: the HREF with
embedded newline, the SRC with trailing spaces, and IMG tag spread over
multiple lines.

<a href="myself.html
">
<img src="/images/picture.gif " width="80"
height="65"
alt="What, me worry?"></a>



<span id=foo onclick="alert(''Don\''t \
forget&nbsp;to include &#x5C;
this'')">Click me</span>

Csaba Gabor from Vienna



Harlan Messinger wrote:

What rules deal with attribute values with trailing spaces, or tags or
attribute values with embedded newlines? Examples below: the HREF with
embedded newline, the SRC with trailing spaces, and IMG tag spread over
multiple lines.

<a href="myself.html
">
<img src="/images/picture.gif " width="80"
height="65"
alt="What, me worry?"></a>



Space characters (space, tab, form feed, new line) are not significant
and being collapsed to a single space by parser (unless in <pre>
block).

This is HTML rule equal for all UA''s (including Amaya).

You may want to watch instead line breaks and spaces *between* tag
because on some surrent implementations it leads to phantom nodes in
DOM Tree.


这篇关于白色空间,标签中的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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