By Chen Hui Jing / @hj_chen
Grid Layout is a new layout model for CSS that has powerful abilities to control the sizing and positioning of boxes and their contents.
Unlike Flexible Box Layout, which is single-axis–oriented, Grid Layout is optimized for 2-dimensional layouts.
Source: CSS Grid Layout Module Level 1Gecko: intent to ship in Firefox 52 (7 March, 2017)
Blink: intent to ship in Chrome 57 (14 March, 2017)
Webkit: ships in Safari 10.1 (release date March/April-ish)
Edge: on the backlog with High priority 🤷
Enable the flag called Enable experimental Web Platform features going to:
chrome://flags/#enable-experimental-web-platform-features
Enable the flag called layout.css.grid.enabled going to:
about:config
Enable the flag called Enable experimental Web Platform features going to:
opera://flags/#enable-experimental-web-platform-features
In Safari Technology Preview and WebKit Nightly Builds you can enable the experimental feature called CSS Grid using the menu: Develop > Expermiental Features > CSS Grid
Set the environment variable
WEBKITGTK_EXPERIMENTAL_FEATURES
:
$ export WEBKITGTK_EXPERIMENTAL_FEATURES="CSS_GRID_LAYOUT=1"
CSS Writing Modes Level 3 defines CSS features to support for various international writing modes, such as left-to-right (e.g. Latin or Indic), right-to-left (e.g. Hebrew or Arabic), bidirectional (e.g. mixed Latin and Arabic) and vertical (e.g. Asian scripts).
You can make your browser literally turn on its side from left-to-right.
🙃Or make it read from right-to-left.
🙂Vertical text is fun!
Centring things is no fun
See the Pen Vertical layout behaviour by Chen Hui Jing (@huijing) on CodePen.
margin-top: auto;
margin-bottom: auto;
Browser support: CSS Writing Mode
Can I Use css-writing-mode? Data on support for the css-writing-mode feature across the major browsers from caniuse.com.
Introduces logical properties and values that provide the author with the ability to control layout through logical, rather than physical, direction and dimension mappings.
Source: CSSWGstart
and end
vs. left
and right
Browser support: CSS Logical Properties
Can I Use css-logical-props? Data on support for the css-logical-props feature across the major browsers from caniuse.com.
Disclaimer: If you're reading this from the future, maybe can.Disclaimer: you cannot learn CSS grid overnight.
It'd be nice if you read the specification 🤓
Grid container | Grid item |
---|---|
|
|
.container {
display: grid;
grid-column-gap: 1em;
grid-row-gap: 1em;
}
.top-left {
grid-row: 1 / 2;
grid-column: 1 / 2;
align-self: center;
justify-self: end;
}
.top-right {
grid-row: 1 / 2;
grid-column: 2 / 3;
align-self: center;
justify-self: start;
}
.bottom {
grid-column: 1 / 3;
grid-row: 2 / 3;
justify-self: center;
}
fr
→ represents a fraction of the free space in the grid container.
.container {
display: grid;
grid-template-columns: 3.6em 1fr;
grid-column-gap: 0.5em;
grid-row-gap: 1em;
}
.left {
grid-row: 1 / 2;
align-self: center;
}
.top-right {
grid-row: 1 / 2;
grid-column: 2 / 3;
align-self: center;
justify-self: start;
}
.bottom {
grid-column: 1 / 3;
grid-row: 2 / 3;
justify-self: center;
}
repeat()
→ represents a repeated fragment of the track list
.outer-container {
display: grid;
grid-template-columns: 1fr 2em;
}
.inner-container {
grid-column: 1 / 2;
grid-row: 1 / 2;
display: grid;
grid-column-gap: 0.5em;
grid-row-gap: 1em;
@media all and (max-width: 719px) {
grid-template-columns: repeat(2, 1fr);
}
@media all and (min-width: 720px) and (max-width: 1279px) {
grid-template-columns: repeat(3, 1fr);
}
@media all and (min-width: 1280px) {
grid-template-columns: repeat(4, 1fr);
}
}
.right {
align-self: center;
grid-column: 2 / 3;
grid-row: 1 / 2;
}