样式表与“< link>”上的TITLE属性分开标签? [英] Style sheets break with TITLE attribute on <link> tags?

查看:129
本文介绍了样式表与“< link>”上的TITLE属性分开标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力升级一个非常旧的企业内联网。我们的用户在IE8和IE9上。我们的大部分网站都是在IE5下编写的 - IE9。



我们正在将所有人升级到IE11,并且飞行员正在发现大量的兼容性问题。未来几个月会有很多补救措施,以及明智地使用企业模式,兼容模式,X-UA标签等。

但是我遇到了一个毫无意义的奇怪问题。它看起来像一个错误,但:


  • 它发生在IE11边缘模式,Chrome和Firefox中。

  • 我在运行IIS 6和IIS 7.5的服务器上重现了这个问题,因为
    和我的桌面一样好。

  • 使用.asp,.htm和。 aspx文件类型。



问题如下:



具有两个链接样式表的网页,并且这两个标签都具有标题属性,则不应用第二个样式表中定义的样式,除非(a)标题属性完全匹配,或(b)其中一个标题属性为空。



例如: $ b

一切正常,如果您的< link> 标记具有相同的标题属性:

 < link REL =stylesheetHREF =a.cssTYPE =text / cssTITLE =1> 
< link REL =stylesheetHREF =b.cssTYPE =text / cssTITLE =1>

如果其中一个标题属性为空:

 < link REL =stylesheetHREF =a.cssTYPE =text / css TITLE = 1 > 
< link REL =stylesheetHREF =b.cssTYPE =text / cssTITLE =>

如果其中一个标签没有TITLE属性,那么一切正常。

 < link REL =stylesheetHREF =a.cssTYPE =text / cssTITLE =1> 
< link REL =stylesheetHREF =b.cssTYPE =text / css>

但是...如果您在标题中有不同的值属性,第二个样式表将不会被应用。

 < link REL =stylesheetHREF =a.cssTYPE =text / cssTITLE =1 > 
< link REL =stylesheetHREF =b.cssTYPE =text / cssTITLE =2>

我已经辞职了,因为我们将不得不扫描最后一页我们的Intranet寻找带有< link> 标签的 title 属性的页面,但我真的很想理解为什么这发生了。最有趣的是,这发生在我尝试过的每个现代浏览器中。如果您强制IE 11进入企业模式或兼容视图,问题就会消失。

任何人都可以解释发生了什么,或者提出一个解决方案,除了从< code>< code>< code> ;链接> 标签?

解决方案

这似乎是预期的行为。例如, MDN文档


首选的样式表是一个值为 stylesheet rel c $ c>属性,以及 title 属性的所有值。这里有两个例子:

 < link type =text / css =stylesheettitle =基本风格 href =basic.css/> 
< link type =text / css =stylesheettitle =鱼和小船href =ocean.css/>

根据HTML 4.01规范,一次只能使用一个首选样式表。因此,根据上述示例,只有两个首选样式表中的一个将应用于文档。该规范没有提供决定使用哪一个的程序,因此用户代理可以自由地做出他们喜欢的任何选择。



I'm helping with an effort to upgrade a very old corporate intranet. Our users are on IE8 and IE9. Most of our sites are written to work in IE5 - IE9.

We're on the verge of upgrading everyone to IE11, and pilots are finding a ton of compatibility issues. There will be a great deal of remediation in the months ahead, as well as judicious use of Enterprise Mode, Compatibility Modes, X-UA tags, and so on.

But I've encountered one strange problem that doesn't make any sense. It seems like a bug, but:

  • It happens in IE11 edge mode, Chrome, and Firefox.
  • I've duplicated the problem on servers running IIS 6 and IIS 7.5, as well as from my desktop.
  • Happens with .asp, .htm, and .aspx file types.

Here's the issue:

If you have a web page with two linked style sheets, and both tags have a title attribute, the styles defined in the 2nd style sheet are not applied unless either (a) The title attributes match exactly, or (b) one of the title attributes is empty.

For example:

Everything works fine if your <link> tags have identical title attributes:

<link REL="stylesheet" HREF="a.css" TYPE="text/css" TITLE="1">
<link REL="stylesheet" HREF="b.css" TYPE="text/css" TITLE="1">

Everything works fine if one of the title attributes is blank:

<link REL="stylesheet" HREF="a.css" TYPE="text/css" TITLE="1">
<link REL="stylesheet" HREF="b.css" TYPE="text/css" TITLE="">

And everything works fine if one of the tags has no TITLE attribute:

<link REL="stylesheet" HREF="a.css" TYPE="text/css" TITLE="1">
<link REL="stylesheet" HREF="b.css" TYPE="text/css">

But… if you have different values in the title attributes, the 2nd style sheet will not be applied.

<link REL="stylesheet" HREF="a.css" TYPE="text/css" TITLE="1">
<link REL="stylesheet" HREF="b.css" TYPE="text/css" TITLE="2">

I've resigned myself to the fact that we're going to have to scan every last page on our Intranet looking for pages with title attributes attached to <link> tags, but I really would like to understand why this is happening. What's most interesting is that this happens in every modern browser I've tried. If you force IE11 into Enterprise Mode or Compat View, the problem goes away.

Can anyone explain what's happening, or propose a solution besides removing title attributes from <link> tags?

解决方案

This appears to be expected behavior. From, for example, the MDN docs

A preferred stylesheet [...] is one that has a value of stylesheet supplied for the rel attribute, and any value at all for the title attribute. Here are two examples:

<link type="text/css" rel="stylesheet" title="Basic styles" href="basic.css" />
<link type="text/css" rel="stylesheet" title="Fish and boats" href="ocean.css" />

According to the HTML 4.01 specification, only one of the preferred stylesheets can be used at a time. Therefore, given the above example, only one of the two preferred stylesheets will be applied to the document. The specification does not supply a procedure to decide which one should be used, so user agents are free to make whatever choice they like.

这篇关于样式表与“&lt; link&gt;”上的TITLE属性分开标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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