而不是
?" />

为什么
而不是

发布于 2024-09-29 21:38:09 字数 283 浏览 0 评论 0 原文

我刚刚意识到:

<div class="clear"/>

在一系列浮动 div 导致布局混乱之后,虽然

<div class="clear"></div> 

工作正常。

谁能解释一下吗?

这是CSS:

div.clear {
    clear:both;
}

I just realized that:

<div class="clear"/>

after a series of floating divs causes layout havoc, while

<div class="clear"></div> 

works fine.

Can anyone explain this?

This is the CSS:

div.clear {
    clear:both;
}

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

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

发布评论

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

评论(3

去了角落 2024-10-06 21:38:09
<div class="clear"/>

如果您将 XHTML 页面作为 text/html 提供,浏览器不会使用真正的 XML 解析器来读取它。他们使用的是一个普通的旧 HTML 解析器,它不知道自闭合标签。对于 HTML4 解析器来说,这只是一个开放标签,其中包含一些奇怪的标点符号。 (如果浏览器解析器真的使用了 SGML 规则,那将是完全不受欢迎的事情,但事实并非如此。)

在 IE9 普及之前,我们将无法将通用网页作为 应用程序提供服务/xhtml+xml,这是让浏览器使用真正的XML解析规则所需要的。在那之前,如果您编写 XHTML 文档,您将需要使您的文档也向后兼容纯 HTML,这意味着始终在元素上使用自闭合语法被声明为具有 EMPTY 内容模型。 (imgbr 等)

关于编写与 HTML 兼容的 XHTML 必须执行的操作还有更多规则,但这是最重要的规则。 XHTML 1.0 标准的附录 C 列出了差异;它看起来有点复杂,但是许多点都涉及您不想使用的功能,并且有些现在已经无关紧要,因为它们正在谈论像 Netscape 4 这样的古老浏览器。 在 >

<div class="clear"/>

If you are serving an XHTML page as text/html, browsers aren't reading it using a real XML parser. They're using a plain old HTML parser which doesn't know about self-closing tags. To an HTML4 parser, that's just an open tag with some weird punctuation in it. (If browser parsers really used the rules of SGML, it would be some other undesirable thing completely, but they don't.)

Until IE9 becomes widespread, we won't be able to serve general-purpose web pages as application/xhtml+xml, which is what's required to make the browser use real XML parsing rules. Until that time, if you write XHTML documents you will need to make your documents also backwards-compatible with plain HTML, which means always and only using self-closing syntax on elements that are declared to have an EMPTY content model. (img, br, etc.)

There are more rules about what you have to do to write HTML-compatible XHTML, but that's the most important one. Appendix C of the XHTML 1.0 standard is a list of the differences; it looks a bit complicated, but many of the points address features you don't want to be using anyway, and some are now irrelevant as they're talking about being ancient browsers like Netscape 4. The practice of putting a space before /> is no longer required by anything in common use, for example.

欢你一世 2024-10-06 21:38:09

根据 HTML 4.01 规范第 7.5.4 节

标记需要一个结束标签。

According to the HTML 4.01 spec, Section 7.5.4, the <div> tag requires a closing tag.

淑女气质 2024-10-06 21:38:09
<div class="clear"/>  

此语法不是有效的 HTML/XHTML。任何可以包含内容的标签不能是自关闭的(即使标签中不需要任何内容​​。因此包含 div、span、p 等标签的内容永远不能是自闭合标签,相反,不能包含
等内容的标签应始终是自闭合标签。

<div class="clear"/>  

This syntax isn't valid HTML/XHTML. Any tag which can contain content cannot be self closing (even if no content is required in the tag. Therefore content containing tags like div, span, p etc, can never be self closing tags. Conversely, tags which cannot contain content like <br /> should always be self closing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文