多个“样式”属于“跨度”的属性。标签:应该发生什么? [英] Multiple "style" attributes in a "span" tag: what's supposed to happen?

查看:100
本文介绍了多个“样式”属于“跨度”的属性。标签:应该发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下带有两个样式属性的HTML片段:

  < span style =color:bluestyle =font-style:italic>测试< / span> 

在Opera 12.16和Chrome 40中,它显示为蓝色的非斜体文本,而Internet Explorer 9显示蓝色斜体文字。如果有的话,标准说什么应该显示出来?

在HTML,SGML和 XML (1)属性不能重复,并且只能在元素中定义一次

所以你的例子:

 < span style =color:bluestyle =font-style:italic>测试< / span>对于HTML标准,

不符合,并且会导致undefined行为,这就解释了为什么不同的浏览器呈现出不同的结果。






由于没有定义的解释方式,浏览器可以(1):我可以找到的每篇文章都指出,属性是键/键,键/键值对或属性值对,这暗示着这些键必须是唯一的。 我可以找到的最佳资源状态

$ b


属性名称(本例中为id和status)受到与其他XML中的名称;但是,在整个DTD中,它们不必是唯一的,但是,只能在给定元素的属性列表中 (Emphasis mine。)



Consider the following HTML fragment with two style attributes:

<span style="color:blue" style="font-style:italic">Test</span>

In Opera 12.16 and Chrome 40, it shows up as blue non-italic text, while Internet Explorer 9 shows blue italic text. What, if anything, does the standard say is supposed to show up?

解决方案

In HTML, SGML and XML, (1) attributes cannot be repeated, and should only be defined in an element once.

So your example:

<span style="color:blue" style="font-style:italic">Test</span>

is non-conformant to the HTML standard, and will result in undefined behaviour, which explains why different browsers are rendering it differently.


Since there is no defined way to interpret this, browsers can interpret it however they want and merge them, or ignore them as they wish.

(1): Every article I can find states that attributes are "key/value" pairs or "attribute-value" pairs, heavily implying the keys must be unique. The best source I can find states:

Attribute names (id and status in this example) are subject to the same restrictions as other names in XML; they need not be unique across the whole DTD, however, but only within the list of attributes for a given element. (Emphasis mine.)

这篇关于多个“样式”属于“跨度”的属性。标签:应该发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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