Html <span> 中可以有 <span> 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9089953/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:12:15  来源:igfitidea点击:

Can you have a <span> within a <span>?

htmlcss

提问by Roozbeh15

Here is the story: I'm using SWFObject to insert a Flash object into my page. The embedding eats my span. So, I lose all my CSS for it. I was thinking of moving all of the CSS to the parent so I don't lose my CSS styles when the Flash appears.

故事是这样的:我使用 SWFObject 将 Flash 对象插入到我的页面中。嵌入吃掉了我的span. 所以,我为此失去了所有的 CSS。我正在考虑将所有 CSS 移动到父级,这样当 Flash 出现时我就不会丢失我的 CSS 样式。

I have tried using a spanwithin a span, but I don't think it's working. Is there a reason for this? I don't understand why you could have divwithin a divbut not a spanwithin a span.

我曾尝试span在 a 中使用 a span,但我认为它不起作用。是否有一个原因?我不明白为什么你可以div在 a 中div而不是span在 a 中span

Does it have to do with spansbeing inline?

它与spans内联有关吗?

回答by Pawe? Bulwan

HTML4 specificationstates that:

HTML4 规范指出:

Inline elements may contain only data and other inline elements

内联元素可能只包含数据和其他内联元素

Span is an inline element, therefore having span inside span is valid. There's a related question: Can <span> tags have any type of tags inside them?which makes it completely clear.

Span 是一个内联元素,因此 span 在 span 内是有效的。有一个相关的问题:<span> 标签可以在其中包含任何类型的标签吗?这使它完全清楚。

HTML5 specification(including the most current draft of HTML 5.3dated November 16, 2017) changes terminology, but it's still perfectly valid to place span inside another span.

HTML5 规范(包括2017 年 11 月 16 日最新的HTML 5.3草案)更改了术语,但将 span 放在另一个 span 中仍然完全有效。

回答by bookcasey

Yes. You can have a spanwithin a span. Your problem stems from something else.

是的。您可以spanspan. 你的问题源于别的东西。