HTML体中的样式和脚本标记......为什么不呢? [英] style and script tags in HTML body... why not?

查看:87
本文介绍了HTML体中的样式和脚本标记......为什么不呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[这与这个问题有关,但不是因为它与电子邮件无关。]



在很多情况下 - 尤其是使用CMS或其他人的框架时,嵌入< style> < body> 中的c>标签和< script> 标签比 < HEAD> 。这似乎适用于IE6,IE7(Windows),Firefox 3.x和Safari(OS X)。



严格地说,这是错误的吗?如果是这样,那么会产生什么负面影响......除了在某些客户中被完全忽略?

谈论DRY并集中风格。想象一下,我想在文档中使用样式标签,因为它们不是全局的,并且我无法在每个页面上访问头部。无论出于何种原因,无论是基于页面还是按照段落基础或其他因素,网站都有所不同。我不感兴趣,很难追查和改变。我担心在体内使用风格可能带来的后果。



你集中了那些重要的东西。

解决方案

尽管规范明确规定了状态标签在body标签中是不允许的,但specs并不重要。样式标签在每个主要浏览器都支持正文,这是用户最终看到您的网站的方式。尽管在浏览器行业中长期以来一直致力于提供更好的标准和标准支持,但长期以来普遍推动呈现中断文档以及可以是。



导致HTML5规范工作的Google同时维护google.com,该规范通过将引号从其引用中删除属性值,对CSS规范使用选择器hack,包括没有类型或语言的脚本标记,以及没有类型的链接标记。纯粹主义者可能会争论说,互联网上使用最多的网站之一违反了规范,并有可能被严重歪曲的严重危险。或者,我们可以推断,没有浏览器会进入流行使用,无法渲染这种广泛使用的规范。



所以,问题更多的是浏览器行业正在走向 - 这又是一个更好的规范之一,但也尽最大努力兑现违反这些规范的网页的意图。我敢打赌,风格标签会在很长一段时间内在体内继续工作。

*在本文中,正文中的样式标签由HTML5文档类型在Firefox 3 +,IE6 +,Safari 2+,Chrome 12+。支持可能会更远,但这些浏览器在互联网上很少见。


[This is related to this question, but not since it's not about email.]

In many cases -- especially when working with a CMS or someone else's framework, it's much easier to embed <style> tags and <script> tags in the <body> than in the <head>. This seems to work in IE6, IE7 (Windows), Firefox 3.x and Safari (OS X).

Strictly speaking, is this wrong? And if it is, what negative consequences might it cause... aside from being completely ignored in some clients?

Note: Glad everybody wants to talk about DRY and centralizing styles. Imagine for a second that I want to use style tags within a document because they ARE NOT GLOBAL and that I DO NOT HAVE ACCESS TO THE HEAD ON A PER-PAGE BASIS. For whatever reason, be it that the site differs on a page-by-page basis, or a per-paragraph basis or whatever. I'm not interested in it being hard to track down and change. I'm worried about possible consequences of using style in the body.

You centralize stuff that's central. Everything else is bloat in the central stylesheets.

解决方案

Although the specs explicitly state style tags are not permitted in the body tag, specs aren't all that matters. Style tags are supported in the body by every major browser, and that's ultimately how users see your site.* While there has long been a drive for better standards and standards support in the browser industry, there's also long been a general push to render broken documents as well as can be.

Google, who leads the HTML5 spec effort, simultaneously maintains google.com which violates specs to save bytes, by leaving the quotes out of its attribute values, using selector hacks against the CSS spec, including script tags with no type or language, and link tags with no type. A purist could argue one of the most used sites on the internet is violating the specs and in serious danger of being horribly misrendered. Or, we can reason that no browser will enter popular use that can't render such widely used hacks on the spec.

So, the question is more of which way the browser industry is going - which again is one of both better specs, but also doing their best to honor the intent of pages that violate those specs. My bet is style tags will keep working in the body for a long time to come.

*As of this writing, style tags in the body are supported with an HTML5 doctype in Firefox 3+, IE6+, Safari 2+, Chrome 12+. Support likely goes back farther but those browsers are rarely seen on the interwebs.

这篇关于HTML体中的样式和脚本标记......为什么不呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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