question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[css-grid] Support named lines

See original GitHub issue

Now names lines are skipped when processing grid-template:

.wrapper {
  display: grid;
  grid-template-columns: [main-start] 1fr [content-start] 1fr [content-end] 1fr [main-end];
  grid-template-rows: [main-start] 100px [content-start] 100px [content-end] 100px [main-end];
}

.box1 {
  grid-column-start: main-start;
  grid-row-start: main-start;
  grid-row-end: main-end;
}

.box2 {
  grid-column-start: content-end;
  grid-row-start: main-start;
  grid-row-end: content-end;
}

.box3 {
  grid-column-start: content-start;
  grid-row-start: main-start;
}

.box4 {
  grid-column-start: content-start;
  grid-column-end: main-end;
  grid-row-start: content-end;
}

Example with repeat

.wrapper {
  display: grid;
  grid-template-columns: repeat(6, [col1-start] 1fr [col2-start] 3fr);
}

.item1 {
  grid-column: col1-start / col2-start 2
}

.item2 {
  grid-row: 2;
  grid-column: col1-start 2 / span 2 col1-start;
}

Description and more examples here https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Layout_using_Named_Grid_Lines

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:12
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Dan503commented, Nov 27, 2018

As mentioned in #1155, there is a use case for line names in having an easy-ish way to have grid areas overlap one another.

.grid {
  grid-template-columns: [a-start] 1fr [b-start] 1fr [a-end] 1fr [b-end];
  grid-template-rows: [a-start] 1fr [b-start] 1fr [b-end] 1fr [a-end];
}
.a {
  grid-area: a;
}
.b {
  grid-area: b;
}

That will produce the same grid as what is shown in this code pen: https://codepen.io/daniel-tonon/pen/BGmXRb

(Although I would personally rather use the grid-column-end: span X; hack instead of reaching for line names to get this effect)

0reactions
aicommented, Mar 5, 2019

We added warning for named lines b54ea06

Read more comments on GitHub >

github_iconTop Results From Across the Web

Grid layout using named grid lines - CSS - MDN Web Docs
Naming lines is useful when creating a responsive design where you redefine the grid, rather than then needing to redefine the content position ......
Read more >
CSS Grid - Using line names - YouTube
The CSS Grid is awesome, but it takes some getting used to. When we want to explicitly place something on the grid, it...
Read more >
Understanding CSS Grid: Grid Lines - Smashing Magazine
In a new series, Rachel Andrew breaks down the CSS Grid Layout specification. ... How to place items according to line name.
Read more >
Using Grid Named Areas to Visualize (and Reference) Your ...
Every named grid area gets four implicitly-named grid lines, two in the column direction and two in the row direction, where -start and...
Read more >
Quick Tip: Name Your CSS Grid Lines, Just in Case
Naming a grid area header automatically assigns names to its four boundary lines too. The row lines around it become header-start and header-end ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found