CSS grid layout explained

CSS Grid
Long Name:CSS Grid Layout Module Level 1
Native Name:CSS Grid Layout Module Level 1
Native Name Lang:en
Status:W3C Candidate Recommendation Draft
First Published:[1]
Version:Level 1
Version Date:[2]
Preview:Level 2
Preview Date:[3]
Organization:W3C
Committee:CSS Working Group
Base Standards:CSS
Abbreviation:Grid, grid layout
Domain:CSS

In Cascading Style Sheets, CSS grid layout or CSS grid creates complex responsive web design grid layouts more easily and consistently across browsers.[4] Historically, there have been other methods for controlling web page layout methods, such as tables, floats, and more recently, CSS Flexible Box Layout (flexbox). CSS grid is currently not an official standard (it is a W3C Candidate Recommendation) although it has been adopted by the recent versions of all current major browsers.[5]

Motivation

CSS grid can create more robust and flexible layouts than the previous options like CSS floats. It also allows for more standardized code that works across browsers. This is in contrast to relying on specific browser hacks or complicated workarounds.

One issue with exploiting floats in CSS is that if content gets added to one portion of the page it could disrupt the flow of the page and break the layout. This is due to the varying heights for layout elements. Though flexbox supports flexible layouts and provides the flexibility of creating complex layouts, it fails when the need for creating responsive layouts in 2-dimensional space arises.

History

The first comprehensive draft of a grid layout for CSS was created by Phil Cupp at Microsoft in 2011 and implemented in Internet Explorer 10 behind a -ms- vendor prefix. The syntax was restructured and further refined through several iterations in the CSS Working Group, led primarily by Elika Etemad and Tab Atkins Jr. The feature was widely adopted by web developers after evangelism led primarily by Rachel Andrew and Jen Simmons.[6]

Browser support

As of October 2017, Chrome, Firefox, Safari and Edge all support CSS grid without vendor prefixes.[7] [8] [9] IE 10 and 11 support CSS grid but with an outdated specification. On mobile, all modern browsers support CSS grid except for Opera Mini.[10] Web developers targeting older browsers can utilize Modernizr 3.5.0 to detect and gracefully degrade the webpage as needed.[11]

Utilization in frameworks

Tailwind CSS incorporates CSS grid into its utilities for controlling how elements are sized and placed.[12] However many other current web frameworks do not incorporate CSS grid, such as Bootstrap 4 and Foundation 6.[13]

the fr unit

The "fr" unit is often used with CSS grid layout.[14] [15] [16] The "fr" unit, part of the CSS grid layout specification, represents a fraction of the leftover space in the grid container.

Examples

"Holy grail" layout

The following is an example of the "holy grail" layout:

Table of values

The following is an example of a table of values:

External links

Notes and References

  1. Web site: CSS Grid Layout Module Level 1 Publication History - W3C. n.d.. 2021-04-09. W3C.
  2. Web site: CSS Grid Layout Module Level 1. W3C. CSS Working Group. W3C Working Group. 2021-12-18. 2021-04-09. Tab. Atkins Jr.. Elika. J. Etemad. Rossen. Atanassov. Oriol. Brufau. Alex. Mogilevsky. Phil. Cupp. Markus. Mielke.
  3. Web site: CSS Grid Layout Module Level 2. W3C. CSS Working Group. 2023-03-14. 2023-03-26. Tab. Atkins Jr.. Elika. J. Etemad. Rossen. Atanassov.
  4. Web site: CSS Grid – Table layout is back. Be there and be square.. Google Developers. January 2017. 2021-04-09.
  5. Web site: CSS Grid Layout (level 1) Can I use... Support tables for HTML5, CSS3, etc. 2022-01-12. caniuse.com.
  6. Web site: Gustafson. Aaron. 2017-10-19. The Story of CSS Grid, from Its Creators. 2022-01-12. A List Apart. en-US.
  7. News: Microsoft's newest browser gets a significant boost with EdgeHTML 16. Anderson. Kareem. 13 September 2017. 7 October 2017.
  8. News: Chrome 57 arrives with CSS Grid Layout and API improvements VentureBeat. Protalinski. Emil. 9 March 2017. VentureBeat. 7 October 2017.
  9. Web site: CSS Grid Layout. Can I Use. n.d.. 2021-04-09.
  10. Web site: "grid" | Can I use... Support tables for HTML5, CSS3, etc .
  11. News: Modernizr 3.5.0. Ateş. Faruk. Modernizr News. 2017-04-13. 2021-04-09.
  12. Web site: Grid Column Start / End - Tailwind CSS. 2021-04-13.
  13. Web site: Flexbox grids and frameworks. https://web.archive.org/web/20170216210600/https://gist.github.com/raphaelgoetter/722e4a5843a8598f72d8dd148bd20c18. 2017-02-16. 2017-02-16. 2021-04-09. dead. Raphael. Goetter. GitHub Gist.
  14. Web site: CSS Grid Layout: The Fr Unit. Alligator.io. 2020-09-03. 2021-04-09. DigitalOcean. DigitalOcean.
  15. Web site: Fractional. — Ethan Marcotte. Ethan. Marcotte. Ethan Marcotte. 2018-07-18. 2021-04-09.
  16. Web site: An Introduction to the 'fr' CSS unit. Robin. Rendle. 2017-06-12. 2021-04-09. CSS-Tricks.