包含块规则的原因 [英] Reason behind containing block rule

查看:56
本文介绍了包含块规则的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你把一个师围绕另一个师这样:


< div id =" wrapper">

< div id =" ; child"> ...< / div>

< / div>


....包装器部门将被视为包含孩子的块

除以所有情况除外

1.包装的定位是静态的和

2.定位的孩子是绝对的。


好​​的。所以为什么?为什么一个案例是个例外?当然,CSS标准

委员会背后有一个原因。当然,他们不仅仅是因为反复无常。他们喝醉了吗?

解决方案

" Bill Norton" < bn ***** @ austin.rr.comwrote:


>如果你将一个师围绕另一个师这样包裹:
< div id =" wrapper">

< div id =" child"> ...< / div>
< / div>

...在所有情况下,包装部门将被视为儿童
部门的包含区块,除非

1.包装器的定位是静态的

2.孩子的定位是绝对的。

好的。所以为什么?为什么一个案例是个例外?当然,CSS标准委员会背后有一个理由。当然,他们不仅仅是反复无常的。他们喝醉了吗?



我不确定你在问什么。


在绝对定位模型中,一个绝对定位的元素是

相对于最近的祖先定位,其位置属性

已被设置为静态的(默认)值以外的任何值。


绝对定位的元素完全从流程中取出,

总是根据它们的父元素

元素定位它们是没有意义的。根据定义,我们可以选择哪个祖先元素作为包含块的

,从而产生可用的方案。


这是否可以回答您的问题?


-

Spartanicus




" Spartanicus" < in ***** @ invalid.invalidwrote in message

news:c1 ************************* ******* @ 4ax.com ...


在绝对定位模型中,一个绝对定位的元素是

定位的尊重最近的祖先,其位置属性

已被设置为静态的(默认)值以外的任何值。



对。这就是它的定义方式。这个问题实际上与*为什么*它确定了这个问题。


绝对定位的元素完全从流程中取出,它b / b
总是根据他们的父母

元素定位它们是没有意义的。根据定义,我们可以选择哪个祖先元素充当包含块的

,从而产生可用的方案。



好​​的。但是我很难想象一个案例,我想要在他父母之外定位一个元素。无论如何,如果想要给我一个关于我想要定位的块的选择,那么为什么不让我完全具体一点呢,比如说,一个容器区财产

像这样:


#divX {position:absolute;左:0px;顶部:0px; container-block:

divWhatever}


" Bill Norton" < bn ***** @ austin.rr.comwrote:


>绝对定位的元素从流程中取出完全地说,总是根据父母的元素来定位它们是没有意义的。根据定义,我们可以选择哪个祖先元素充当包含块,从而产生可用的方案。


好的。但是我很难想象一个我希望将一个元素放在其父元素之外的情况。



使用你需要的东西,留下你不想要的东西。我认为没有任何理由

批评CSS提供比你个人需要更多的选择。


-

Spartanicus


If you wrap one division around another like this:

<div id="wrapper">
<div id="child">...</div>
</div>

....the wrapper division will be considered the containing block of the child
division in all cases except where
1. the positioning of the wrapper is static and
2. the positioning of the child is absolute.

OK. So why? Why is that one case an exception? Surely the CSS standards
committee had a reason behind this. Surely they weren''t just being
capricious. Were they drunk?

解决方案

"Bill Norton" <bn*****@austin.rr.comwrote:

>If you wrap one division around another like this:

<div id="wrapper">
<div id="child">...</div>
</div>

...the wrapper division will be considered the containing block of the child
division in all cases except where
1. the positioning of the wrapper is static and
2. the positioning of the child is absolute.

OK. So why? Why is that one case an exception? Surely the CSS standards
committee had a reason behind this. Surely they weren''t just being
capricious. Were they drunk?

I''m not sure what you are asking.

In the absolute positioning model an absolutely positioned element is
positioned with respect to the nearest ancestor whose position property
has been set to anything other than the (default) value of static.

Absolutely positioned elements are taken out of the flow completely, it
would make no sense to always position them in respect to their parent
element. As defined we can choose which ancestor element acts as the
containing block which results in a usable scheme.

Does that answer your question?

--
Spartanicus



"Spartanicus" <in*****@invalid.invalidwrote in message
news:c1********************************@4ax.com...

In the absolute positioning model an absolutely positioned element is
positioned with respect to the nearest ancestor whose position property
has been set to anything other than the (default) value of static.

Right. That''s how it''s defined. The question really had to do with *why* it
was defined that way.

Absolutely positioned elements are taken out of the flow completely, it
would make no sense to always position them in respect to their parent
element. As defined we can choose which ancestor element acts as the
containing block which results in a usable scheme.

OK. But I''m having a hard time imagining a case where I would want to
position an element outside of its parent. And anyway if the idea is to give
me a choice as to which block I want to position something, then why not let
me be completely specific about it with, say, a container-block property
like this:

#divX {position: absolute; left: 0px; top: 0px; container-block:
divWhatever}


"Bill Norton" <bn*****@austin.rr.comwrote:

>Absolutely positioned elements are taken out of the flow completely, it
would make no sense to always position them in respect to their parent
element. As defined we can choose which ancestor element acts as the
containing block which results in a usable scheme.


OK. But I''m having a hard time imagining a case where I would want to
position an element outside of its parent.

Use what you need, leave the bits that you don''t. I see no justification
for criticizing CSS for offering more options than you personally need.

--
Spartanicus


这篇关于包含块规则的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆