html - 是否需要使用带有 <div> 的结束标记来清除 float ?

标签 html css css-float

<分区>

当使用clear:both样式的DIV元素清除之前的 float 时,是否需要在DIV元素上使用开始结束标签?这是一个例子......

这样可以吗?

<div style="clear:both;" />

还是应该这样?

<div style="clear:both;"></div>

最佳答案

你需要结束标签,或者浏览器will not think the tag is closed .

但是,您为什么还要使用 <div style="clear:both;"></div> ?这涉及添加额外的非语义 div没有理由。

有更好的方法来包含/清除 float :

  • 使用overflow: hidden在包含您的花车的元素上。
  • 或者,使用 clearfix,例如 "micro clearfix" .

关于html - 是否需要使用带有 <div> 的结束标记来清除 float ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9279244/

上一篇:css - 几个 CSS 继承问题

下一篇:javascript - 如何使用其标签名称获取特定元素?

相关文章:

html - 填充 float 元素

html - 在 td 中添加另一个图像?

html - 将文本正确放置在居中图像下方

html - 我如何设计一个 css 渐变看起来像附加的 Facebook 登录屏幕

jquery - 如何以编程方式在鼠标悬停链接上滑动图像

html - CSS 重置后两个元素上的相同样式不同(仅限 IE)

html - 如何制作一个div(宽度: auto) adjust to nested divs (float left and fixed width)

javascript - 错误: Not getting a desired output

javascript - 适配textarea max word插件

html - 嵌套在 HTML5 中