An Event Apart: Fit for Purpose – Making Sense of the New CSS
by Laurence Hughes
At An Event Apart Chicago 2018, Eric Meyer, author of CSS: The Definitive Guide and co-founder of An Event Apart, described some real-world front-end challenges, and how he evaluated the new CSS features at his disposal and arrived at appropriate decisions. Here are my notes and to-dos.
@supports (prop: val) works like a bridge to newer features for those browsers which understand them.
Check support for CSS variables like so: @supports (--css: variables) { /* variable-dependent stuff goes here */ }
CSS variables can be reassigned (unlike Sass variables).
If you need to test support for multiple things simultaneously, you can use compound @supports (prop: val) and (prop: val) statements or you can nest @supports statements.
Flex is really useful for getting things to line up. Both centre-alignment (e.g. a list of social media icons at slightly different dimensions) and also e.g. boxes in a row with variable content that all stay the same height.
margin-right: auto; e.g. on a logo which has nav links to right; or margin-top: auto; e.g. on a footer element, is very useful!
justify-content: flex-start is intelligent in that if the document language changed to a right-to-left language, your items (e.g. nav links) would automatically start from the right rather than the left.
CSS Grid is an amazing prototyping tool for quickly turning a design comp into a web page for closer evaluation.
Do partial-width borders underneath headings or other elements: background: linear-gradient(rgba(0,0,0,0.67), rgba(0,0,0,0.67)) no-repeat bottom left / 50% 0.5ch;