Grid properties not working on elements inside grid container

前端 未结 1 2052
清歌不尽
清歌不尽 2020-11-22 09:32

I\'m trying to position a nested li (ul li ul li) on a CSS Grid created on the top-most ul. No love yet (it\'s not working). Maybe it\

相关标签:
1条回答
  • 2020-11-22 09:56

    The scope of a grid formatting context is limited to a parent-child relationship.

    This means that a grid container is always the parent and a grid item is always the child. Grid properties work only within this relationship.

    Descendants of a grid container beyond the children are not part of grid layout and will not accept grid properties.

    You're trying to apply grid properties to elements that are descendants, but not children, of a grid container. Those elements are outside the scope of grid layout.

    Bottom line: You will always need to apply display: grid or display: inline-grid to a parent in order to apply grid properties to the child.

    Note that grid items can also be grid containers.

    Also see:

    • Positioning content of grid items in primary container (subgrid feature)
    • Proper use of flex properties when nesting flex containers
    • Is it bad practice to nest CSS Grids?
    0 讨论(0)
提交回复
热议问题