Clear inside div A 正在清除 div A 外部的 div B 的浮动

发布于 2024-09-08 14:39:48 字数 243 浏览 1 评论 0原文

这是我在尝试创建带有侧边栏的布局时多次遇到的问题。

我在这里举了一个例子: http://samutz.com/div.html

#content 里面有东西只需要在 #content 内浮动然后清除。但是当我尝试清除#content内部时,它也会清除#sidebar的浮动,尽管#sidebar位于#content之外。

This is a problem I've had several times when trying to create layouts with a sidebar.

I made an example here: http://samutz.com/div.html

#content has stuff inside it that needs to float and then clear within #content only. But when I try to clear inside #content, it clears the #sidebar's float as well, despite #sidebar being outside of #content.

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

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

发布评论

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

评论(1

自控 2024-09-15 14:39:48

选项A:

  1. 从#cleared Wrap #floating中删除clear:both到
  2. 另一个div内,给新的div overflow:hidden; Zoom:1;

如果这弄乱了 #content 文本,请将文本放入这个新的 div 中:

http:// /medero.org/clear2.html

溢出技术说明:http://work.arounds .org/clearing-floats/

选项 B:

您也可以绝对定位侧边栏,但如果它变长,您可能不得不弄乱最小高度。

额外:

如果您需要将侧边栏包含在主包装器中:

http://medero。 org/clear3.html

Option A:

  1. Remove clear:both from #cleared
  2. Wrap #floating inside another div, give the new div overflow:hidden; zoom:1;

If this messes up #content text, put the text inside this new div:

http://medero.org/clear2.html

Explanation for overflow technique: http://work.arounds.org/clearing-floats/

Option B:

You can also absolutely position the sidebar but you might have to mess with min-heights if it becomes long.

Extra:

If you need to contain the sidebar with your main wrapper:

http://medero.org/clear3.html

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