Html XHTML 中的嵌套 span 标签是否正常?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1078127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Are nested span tags OK in XHTML?
提问by rick
Will this validate in XHTML?
这会在 XHTML 中验证吗?
<span>hello<span>world</span></span>
采纳答案by RichardOD
Yes it will. You can help yourself by using the w3's validatordirect input option:
是的,它会。您可以使用w3 的验证器直接输入选项来帮助自己:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Title</title>
</head>
<body>
<p>
<span>Test<span>Nest span</span></span>
</p>
</body>
</html>
回答by joebert
Absolutely.
绝对地。
Here's the definition from an XHTML-strict DOCTYPE for a span element.
下面是一个 XHTML 严格的 DOCTYPE 对 span 元素的定义。
<!ELEMENT span %Inline;> <!-- generic language/style container -->
<!ATTLIST span
%attrs;
>
The "%Inline" part tells me that it can have child nodes from the "% Inline;" entities element list.
"%Inline" 部分告诉我它可以有来自 "% Inline;" 的子节点。实体元素列表。
The span element is included in the list of elements classed as "% Inline", that combined with span allowing "%Inline" child elements tells me that span is a valid child of span.
span 元素包含在归类为“% Inline”的元素列表中,结合 span 允许“%Inline”子元素告诉我 span 是 span 的有效子元素。
回答by dusoft
SPAN can contain only inline elements, such as SPAN etc.
SPAN 只能包含内联元素,例如 SPAN 等。