@rachelandrew
What’s it like being in the middle of a launch of a big new CSS feature?
Slide 6
@rachelandrew
It involved a lot of email.
Slide 7
@rachelandrew
Grid is: •
Exciting - a real game changer
•
Confusing - it doesn’t seem to do what I thought it would
•
Scary - there are so many new properties to learn!
Slide 8
@rachelandrew
“Q. How do you feel when you see a new CSS feature announced?” –Me, in a survey question
Slide 9
@rachelandrew
“Excited but also worried about falling behind.”
–Survey response
Slide 10
@rachelandrew
“Excited, until I share it with colleagues and they pick it apart” –Survey response
Slide 11
@rachelandrew
“Oh no, a new way to have inconsistencies between web browsers.” –Survey response
Slide 12
@rachelandrew
“Tired.”
–Survey response
Slide 13
@rachelandrew
I can’t tell you what to do.
Slide 14
@rachelandrew
I can help you develop the skills to make those decisions yourself.
Slide 15
@rachelandrew
I want you to be the amazing CSS layout person on your team.
Slide 16
@rachelandrew
You need to understand CSS.
Slide 17
@rachelandrew
Understanding CSS is not about learning every property and value by heart. (my main skill is “can use a search engine”)
Slide 18
@rachelandrew
Core ideas that help CSS layout make sense.
Slide 19
@rachelandrew
Cascading Style Sheets
Slide 20
@rachelandrew
Inheritance - which properties will inherit values from their parent.
Slide 21
@rachelandrew
Specificity - which rule wins when two things could apply to the same element.
@rachelandrew
Percentages •
Ugly
•
Easy to understand
•
If they total more than 100% bad things happen.
•
Can be converted from an ideal pixel size using a straightforward calculation.
@rachelandrew
Items start by trying to display at max-content size.
Space is reduced according to the flexbasis. In this case the size of the content.
https://codepen.io/rachelandrew/pen/KXGbQo/
Slide 52
@rachelandrew
https://codepen.io/rachelandrew/pen/KXGbQo/
flex: 1 1 auto; Items can grow and shrink so stretch to fill the container.
With no extra space, items shrink as before.
Slide 53
@rachelandrew
https://codepen.io/rachelandrew/pen/KXGbQo/
flex: 1 1 0; Items can grow and shrink so stretch to fill the container.
With a flex-basis of 0 space is distributed from 0, making equal columns.
Slide 54
@rachelandrew
https://codepen.io/rachelandrew/pen/wrYONK
Flex items at min-content size
Grid items at max-content size
Slide 55
@rachelandrew
Flexbox is starting from max-content and taking space away. Grid starting at min-content and adding space.
@rachelandrew
https://slack.engineering/rebuilding-slack-com-b124c405c193
“In the end, we discovered that a column-based grid wasn’t actually needed. Since Grid allows you to create a custom grid to match whatever layout you have, we didn’t need to force it into 12 columns. Instead, we created CSS Grid objects for some of the common layout patterns in the designs.” –Rebuilding Slack.com
@rachelandrew
https://codepen.io/rachelandrew/pen/QqJbyB/
grid-area: content / content / content ; grid-row-start
grid-column-start
grid-row-end
• grid-column-end is set to the value used for grid-column-start, which is ‘content’.
Slide 91
@rachelandrew
https://codepen.io/rachelandrew/pen/QqJbyB/
grid-area: content / content ; grid-row-start
grid-column-start
• grid-row-end is set to the value used for grid-column-start, which is ‘content’. • grid-column-end is set to the value used for grid-column-start, which is ‘content’.
Slide 92
@rachelandrew
https://codepen.io/rachelandrew/pen/QqJbyB/
grid-area: content ; grid-row-start
• The other three values are set to the same as grid-row-start, so all are set to ‘content’
@rachelandrew
https://codepen.io/rachelandrew/pen/ZXNYob/
Floating the image means the text wraps round.
Defining a grid on the container means we don’t get the wrapping behaviour.
Slide 113
@rachelandrew
https://codepen.io/rachelandrew/pen/RLmNvY/
Multi-column layout splits content into equal width columns.
Using column-width of 200px means we get more columns if there is room, fewer with less available width.
Slide 114
@rachelandrew
https://codepen.io/rachelandrew/pen/OxYVmL
Flex items with the value of justify-content set to space-between.
I also use flexbox to centre the word in the circle.
Slide 115
@rachelandrew
You don’t need a grid-shaped hammer for every layout task.
Slide 116
@rachelandrew
Off-the-shelf frameworks are designed to solve generic problems.
Slide 117
@rachelandrew
Do you want your project to inherit the CSS issues of the rest of the world?
Slide 118
@rachelandrew
Build your own framework* * framework doesn’t mean “all-encompassing behemoth”
Slide 119
@rachelandrew
Solving your specific problems only will result in lighter, easier to understand code
@rachelandrew
Building confidence in your CSS skills will help you to make your case to use newer methods. (Although quite often asking permission is optional)
Slide 127
@rachelandrew
Old browser versions
of survey respondents cited IE11 as oldest IE supported.
Slide 128
@rachelandrew
Old browser versions
of survey respondents support IE10+
Slide 129
@rachelandrew
https://rachelandrew.co.uk/archives/2016/11/26/should-i-try-to-use-the-ie-implementation-of-css-grid-layout/
IE10 & 11 have the -ms prefixed older version of grid layout.
Slide 130
@rachelandrew
For other desktop browsers supporting the last 2 versions is common.
@rachelandrew
Many browsers without support for Grid and other new CSS at this point are mobile browsers.
Slide 141
@rachelandrew
Many of the browsers without support are most popular in areas where data is expensive or devices less powerful.
Slide 142
@rachelandrew
“Grid too young and would need a ton of polyfills.” “Lack of a good css grid polyfill that works with postcss and supports not so old browsers” –Survey responses
Slide 143
@rachelandrew
Stop looking for polyfills and shims. They will make the experience worse for less capable browsers and devices.
Slide 144
@rachelandrew
“The time it takes your customer to get the information she came for.” –Jeffrey Zeldman
Slide 145
@rachelandrew
Using Grid rather than loading a big framework can help create a better experience even for browsers that don’t support Grid.
Slide 146
@rachelandrew
Feature Queries - use CSS to ask if the browser supports a feature before using it.