清除div中的内容A清除div B的浮点数,它位于div A之外

Sam*_*utz 9 html css layout clear css-float

这是我尝试使用侧边栏创建布局时多次遇到的问题.

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

#content里面有东西需要浮动然后才在#content中清除.但是,当我尝试清除里面#内容,它会清除#侧边栏的浮动为好,尽管#sidebar是#内容之外.

med*_*iev 5

选项A:

  1. 删除clear:都来自#cleared
  2. 在另一个div中包装#floating,给出新的div overflow:hidden; zoom:1;

如果这会弄乱#content文本,请将文本放在这个新div中:

http://medero.org/clear2.html

溢出技术的解释:http://work.arounds.org/clearing-floats/

选项B:

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

额外:

如果您需要包含带有主包装的侧栏:

http://medero.org/clear3.html