什么格式的上下文适用于不创建自己的元素? [英] What formatting context applies to elements that don't create their own?

查看:77
本文介绍了什么格式的上下文适用于不创建自己的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我阅读CSS Visual格式规范时,我看到了

When I read the CSS Visual formatting specification, I see that

普通流中的框属于格式上下文,在CSS 2.2中可以是表,块或内联.块级框参与块格式化上下文.内联级别框参与内联格式设置上下文.

Boxes in the normal flow belong to a formatting context, which in CSS 2.2 may be table, block or inline. Block-level boxes participate in a block formatting context. Inline-level boxes participate in an inline formatting context.

但并非所有方框都创建一个块格式上下文.它在文档中的何处描述了不创建BFC的框的正常流程,如果不创建BFC,则适用什么格式的上下文?

But not all boxes create a Block Formatting Context. Where in the docs does it describe the normal flow for boxes that don't create a BFC, and if they don't create one, what formatting context applies?

.container {
    background-color: red;

    /*overflow: hidden; !* creates a block formatting context *!*/
}

p {
    background-color: lightgreen;
    margin: 10px 0;
}

<div class="container">
    <p>Sibling 1</p>
    <p>Sibling 2</p>
</div>

例如,在此代码中,如果我取消注释overflow: hidden;,则div将获得BFC,但之前是什么?

For example in this code, if I uncomment overflow: hidden; the div gets a BFC, but what it was before?

推荐答案

简单地说,每个块都位于格式化上下文中.没有特殊属性的块(例如,没有附加CSS的div)都位于其父级的格式设置上下文中.

Put simply, every block sits in a formatting context. Blocks that have no special properties (e.g. divs with no extra CSS attached) all sit in their parent's formatting context.

仅当块具有positionfloatopacity等属性时,才会为该块及其内容创建新的格式设置上下文.

Only when a block has properties like position, float, opacity etc., does a new formatting context get created for the block and its contents.

要回答您的问题,当一个块没有创建自己的BFC时,它叫什么,这就是W3C页面所谓的正常流".

And to answer your question what's it called when a block does not create a BFC of its own, that's simply what the W3C page calls "normal flow".

这篇关于什么格式的上下文适用于不创建自己的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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