Does the CSS flexbox module work on direct child elements only?

前端 未结 3 639
北海茫月
北海茫月 2020-12-05 10:41

Have a look at this page design of a site I own and run:

http://www.jungledragon.com/image/9472/barn_owl_close-up.html

As you can see, this concerns a classi

3条回答
  •  执念已碎
    2020-12-05 11:14

    To answer your question title: yes, this is actually stated quite clearly in the spec:

    The contents of a flex container consists of zero or more flex items: each child of a flex container becomes a flex item

    In case the wording in the spec confuses you, that's because your wording is a bit off:

    They are childs but not direct childs.

    A child is direct by definition... the inner divs are called descendants, but not children in that they're not directly nested within the flex container.

    Now, anything with display: flex or display: inline-flex is designated a flex container. While each flex item participates in the flex container's formatting context, the flex item's descendants are formatted independently and regardless of the flex container, being the same as if the container was never flexed in the first place.

    As such, you can't reorder descendants of flex items, except if the flex item itself is also made a flex container for its descendants, but even then you cannot reorder them beyond this inner container and around the container's siblings with respect to the outer container.

提交回复
热议问题