[css-grid] grid area as element
Nobody has claimed this yet.
- Dominant language
- Bikeshed
- Stars
- 4.9k
- Forks
- 816
- PR merge metrics
- PR metrics pending
Description
I love the idea of grid areas to place items. They reduce the need for layout wrapper elements that have no semantic meaning. However, I still require wrapper elements for nested layouts, e.g. a dynamic flex layout inside a grid cell.
I would love to be able to target a grid area and use and style it just like a wrapper element. I don't know if this is feasible at all, but this would (in most cases) completely eliminate the need for any layout wrapper elements.
As an example markup:
<div class="grid">
<div class="header">...</div>
<div class="menu">...</div>
<div class="footer">...</div>
<div class="content">...</div>
<div class="content">...</div>
<div class="content">...</div>
<div class="content">...</div>
</div>
The css:
.grid {
display: grid;
grid-template-columns: auto 1fr;
grid-template-rows: auto 1fr auto;
grid-template-areas:
'header content'
'menu content'
'footer content';
}
.grid:grid-area(content) {
display: flex;
flex-wrap: wrap;
outline: 1px solid black;
}
.header {
grid-area: header;
}
.menu {
grid-area: menu;
}
.content {
grid-area: content;
}
.footer {
grid-area: footer;
}
As a result, the DOM structure is completely flattened and only contains actual content. The css completely controls the layout, including the nested dynamic flow of the .content items.
Using the (suggested) accessor :grid-area, the items within this area are placed using a flex flow and wrapped when needed. It would then also be possible to style the area even further as shown with the black border.
Again, I do not know if this is even technically possible with the current implementation of grid, but, to me, this looks like the missing link to combine the power of grid and flexbox.
[edit: updated css suggested selector to :grid-area]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the CSS Grid and flexbox behavior described in the issue, focusing on the proposed :grid-area accessor and how it would target an area rather than an element. Determine whether the requested nested flex layout and area styling are technically feasible, then document a concrete specification direction and its expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100