HTML是?标签也受到脚本和 CSS 的尊重吗?

发布于 2024-08-19 05:53:01 字数 373 浏览 5 评论 0原文

基础 HTML 元素为 HTML 中的相对 URI 提供基础。 JavaScript 和 CSS 也必须遵守其中发出的相对 URI:

例如

JavaScript:

location.href = "mypage.htm"` 

CSS:(

h4 { 
    background-image: url(myimage.gif) 
}

在任何浏览器中?)

The base HTML element provides a base for relative URIs in the HTML. Must JavaScript and CSS also honor it for relative URIs issued in them:

E.g.

JavaScript:

location.href = "mypage.htm"` 

CSS:

h4 { 
    background-image: url(myimage.gif) 
}

(in any browser?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放赐 2024-08-26 05:53:01

CSS 路径始终相对于样式表本身,并且不依赖于 HTML 位置(除非 IE6 有问题且愚蠢并尝试加载 CSS behavior 中指定的 .htc 文件相对于文档的属性)。对于其他内容, 将影响 HTML 的感知当前目录,就好像文件位于 base 定义的目录中一样。因此,它确实会影响 location.href=...; 等内容。顺便说一句,

CSS paths are always relative to the stylesheet itself and have no dependence on the HTML location (except when IE6 is buggy and stupid and tries to load .htc files specified in CSS behavior attributes relative to the document). For other stuff, <base> will affect the perceived current directory of the HTML as if the file was located in the directory defined by base. Consequently, it does affect things like location.href=...;. By the way, inline styles and style information in <style> element are loaded relative to the document location. Those are affected by the <base> tag, of course.

蓝天白云 2024-08-26 05:53:01

base 标签实际上仅受 HTML 文档本身内的相对链接的影响。

然而,在 HTML(而不是 XHTML)中使用 标记时,确实需要考虑一个 IE6 特有的错误。 标记在 HTML 中记录为没有结束标记 ,但 IE6 错误地假定它为 true,这将导致整个内容 标记作为 标记的 放置在其 HTML DOM 中树。这可能会导致 Javascript/jQuery/CSS 中乍一看无法解释的问题,即在特定选择(例如 html>body)中完全无法访问元素,直到您发现实际上有一个 base 之间。

正常的 IE6 修复是使用条件注释来包含结束标记:

<base href="http://example.com/"><!--[if lte IE 6]></base><![endif]-->

The base tag is indeed only honoured by the relative links inside the HTML document itself.

There's however an IE6-specific bug which you really need to take into account when using <base> tag in HTML (not in XHTML). The <base> tag is in HTML documented as not having an end tag </base>, but IE6 incorrectly assumed it for true which will cause that the entire content after the <base> tag is placed as child of the <base> tag in its HTML DOM tree. This can cause at first sight unexplainable problems in Javascript/jQuery/CSS, i.e. the elements being completely unreachable in specific selections (e.g. html>body) until you discover that there's actually a base in between.

A normal IE6 fix is using conditional comments to include the end tag:

<base href="http://example.com/"><!--[if lte IE 6]></base><![endif]-->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文