"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to locate grand elements in a subgrid in a CSS grid container?

How to locate grand elements in a subgrid in a CSS grid container?

Posted on 2025-05-02
Browse:286

Can Subgrids Position Grandchildren Within a CSS Grid Container?

Grid Subgrids: A Way to Position Grandchildren within a Grid Container

While CSS Grid is often depicted as a structure where grid-positioned elements are immediate children of the grid itself, it does offer a mechanism for positioning even "grandchildren" on the grid directly. This is achieved through the display: subgrid property.

Display: Subgrid and Grid Inheritance

According to the CSS Grid Level 2 draft specification, display: subgrid allows a grid item to become a subgrid. This special type of grid container inherits grid parameters from its parent, bypassing its own grid properties and instead adopting the parent's grid tracks.

Practical Implications

With display: subgrid, the children of a grid item can align to the parent grid's lines. This allows grandchildren to be positioned within the grid structure, even though they are not direct descendants of the grid container.

Limitations and Implementation Status

Unfortunately, display: subgrid is not yet supported by major browsers and may not be for some time. Until then, alternative approaches, such as display: grid on grid items or display: contents, can be explored as workarounds.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3