HTML 是?标签也受到脚本和 CSS 的尊重吗?
基础 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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 CSSbehavior
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 likelocation.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.base
标签实际上仅受 HTML 文档本身内的相对链接的影响。然而,在 HTML(而不是 XHTML)中使用
标记时,确实需要考虑一个 IE6 特有的错误。
标记在 HTML 中记录为没有结束标记,但 IE6 错误地假定它为 true,这将导致整个内容
标记作为
标记的 子 放置在其 HTML DOM 中树。这可能会导致 Javascript/jQuery/CSS 中乍一看无法解释的问题,即在特定选择(例如html>body
)中完全无法访问元素,直到您发现实际上有一个base 之间。
正常的 IE6 修复是使用条件注释来包含结束标记:
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 abase
in between.A normal IE6 fix is using conditional comments to include the end tag: