使子项在overflow:hidden parent之外可见 [英] Make child visible outside an overflow:hidden parent
问题描述
在CSS中,在父容器上设置 overflow:hidden
,以允许它扩展其浮动子项的高度。
但与 margin:auto
...
如果PREVIOUS同级是一个浮动元素,它实际上会出现并列。也就是说,如果兄弟节点是 float:left
,那么具有 float:none overflow:hidden
的兄弟姐妹,没有换行 - 就好像它是在正常的流动漂浮。如果前面的兄弟节点是 float:right
,那么容器将出现在兄弟节点的左边。调整此容器的大小将准确地显示它居中在浮动元素之间。假设你有两个以前的兄弟姐妹,一个 float:left
另一个 float:right
这里是问题 b
如何在不隐藏儿童的情况下维护该类型的布局?
web给了我如何清除:两个
和展开一个容器...但我找不到任何替代解决方案维护左/右前儿童中心。如果你使容器 overflow:visible
,那么容器会突然忽略浮动元素的布局流,并在浮动元素的顶部出现。
所以问题:
我必须拥有容器
overflow:hidden
以保留布局... 如何让孩子不被掩盖?
或
我如何 overflow:visible
所以我可以绝对地定位一个孩子相对于父外的容器... YET保留同胞float-like-layout-flow?
您可以使用 clearfix
以同样的方式做布局保留 overflow:hidden
。
.clearfix:before,
.clearfix :after {
content:。;
display:block;
height:0;
overflow:hidden;
}
.clearfix:after {clear:both; }
.clearfix {zoom:1; } / * IE< 8 * /
添加 class =clearfix
class给父级,并删除 overflow:hidden;
In CSS the overflow:hidden
is set on parent containers in order to allow it to expand with the height of their floating children.
But it also has another interesting feature when combined with margin: auto
...
If PREVIOUS sibling is a floating element, it will actually appear juxtapose to it. That is if the sibling is float:left
then the container with float:none overflow:hidden
will appear to the right of the sibling, no newline - just as if it was floating in the normal flow. If the previous sibling is float:right
then the container will appear to the left of the sibling. Resizing this container will accurately show it centered inbetween the floating elements. Say if you have two previous siblings, one float:left
the other float:right
, the container will appear centered inbetween the two.
So here's the problem...
How do I maintain that type of layout WITHOUT masking children?
Googling all over the web gives me ways on how to clear:both
and expand a container... but I can't find any alternative solution to maintaining the left/right previous-child centering. If you make the container overflow:visible
then the container suddenly ignores the layout flow of the floating elements and appears layered ontop of the floating element.
So question:
I have to have the container overflow:hidden
to preserve layout...
how can I make it so the children aren't masked? I need to have the child absolutely positioned relative to the parent outside the container.
OR
How do I overflow:visible
so I can absolutely position a child relative to the parent outside the container... YET preserve the sibling float-like-layout-flow?
You can use the clearfix
to do "layout preserving" the same way overflow: hidden
does.
.clearfix:before,
.clearfix:after {
content: ".";
display: block;
height: 0;
overflow: hidden;
}
.clearfix:after { clear: both; }
.clearfix { zoom: 1; } /* IE < 8 */
add class="clearfix"
class to the parent, and remove overflow: hidden;
这篇关于使子项在overflow:hidden parent之外可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!