#CSS
:is() selector ๐
the successor to :any() and :matches()
sneak peak into our talk, here's a neat gif I made with XD showing what the :is() selector syntax can do. be excited for Chrome Dev Summit y'all!
make taps 300ms faster with 1 line of CSS:
```
#css
touch-action: manipulation;
```
means:
element doesn't want double-tap to zoom
result:
browser *immediately* responds to taps instead of waiting 300ms for a "potential" 2nd tap ๐ค
caniuse (YES!)
Can you believe these slides are full page loads to completely new HTML pagesโฝ
#smashingconf
^ try it with Canary and enable the flag chrome://flags/
#view
-transition-on-navigation
what. rad. tech. ๐คฏ
make focus a little more engaging
```css
@media
(prefers-reduced-motion: no-preference) {
:focus {
transition: outline-offset .25s ease;
outline-offset: 5px;
}
}
```
try it
.logo {
display: flex;
place-items: center;
gap: .5ch;
font-size: 20vmin;
}
.logo > img {
max-block-size: 1.25em;
}
๐คฉ logo img height is 125% of a responsive font-size (20vmin) letter M.. relative units are so cool!
๐ flex that gap in the latest release of Chrome Canary ๐
```css
display: flex; ๐ฆพ
gap: 1ch; ๐ฅ
```
early adopters:
help us test it out won't ya!?
note:
requires web experiments enabled, visit chrome://flags/
#enable
-experimental-web-platform-features in Canary to enable
I can't stop seeing
#CSS
View Transitions!
here I'm animating new `node.textContent`, letting the browser handle the morph while bringing in custom animations (and stagger) for stage enter and stage exit ๐ฅฒ
try it
View Transition powered drag n' drop!
just drag events then swappin DOM,
#CSS
view transitions doin all the animation work (which it's GREAT AT)
๐คฏ
that animated emoji don't miss a beat
try it!
I can't stop seeing
#CSS
View Transitions!
here I'm animating new `node.textContent`, letting the browser handle the morph while bringing in custom animations (and stagger) for stage enter and stage exit ๐ฅฒ
try it
#CSS
media queries conditionally *apply* styles, BUT did you know they can conditionally *load* styles too?
This tasty sip pairs well with a main course of CSS bundle splitting ๐
typography and copy editing ๐ฅ tip
โ word break with <wbr> and/or
```html
<h1>superlongword</h1> <h1>super<wbr>long<wbr>word</h1>
<h1>superlongword</h1>
```
try it!
learn more
```
#CSS
width: calc(50% - 2ch);
min-width: 20ch;
max-width: 70ch;
```
OR
```
width: clamp(20ch, 50% - 2ch, 70ch);
```
aka: optimally half the page minus some space.. but cap it at a healthy reading count of 70 characters while never under 20ch!
play ๐
rgb() โ rgba() just to add transparency? ๐คข
hsl() โ hsla() ... ๐ญ
GOOD NEWS!
fixed in CSS color-level-4,
rgb() & hsl() accept a 4th parameter ๐
color demo
color level 4 docs
๐ฅ tips
- try in your fav browser!
- drop comma's!
`font-size: min(100%, 16px);`
opt your UI out of iOS zooming when inputs are tapped
[video alt]
a <select> element is tapped before and after it's font-size is changed, and in one case the device zooms to the <select>, the other it doesn't
animation happening too fast you can't figure it out? pop open devtools, open the animations panel (), then slow time to 25% or scrub a timeline like me!
.drips ๐
give it a shot on this rad Codepen why don't ya?
Opposing corner radial gradients look softer than angled linear gradients:
#CSS
background-image:
radial-gradient(
circle at top right,
cyan, transparent
),
radial-gradient(
circle at bottom left,
deeppink, transparent
)
;
play
TIL CSS can check for a font installed locally before fetching it remotely!
#perfmatters
Shout out to Dank Mono, my favorite ligature featured coding font
๐ flex that gap in the latest release of Chrome Canary ๐
```css
display: flex; ๐ฆพ
gap: 1ch; ๐ฅ
```
early adopters:
help us test it out won't ya!?
note:
requires web experiments enabled, visit chrome://flags/
#enable
-experimental-web-platform-features in Canary to enable
If I'm making "hover to reveal" UI interactions, I like to put them behind the CSS hover capability media query ๐ค
Then I'm not hiding content from a user who viewing without the capability to reveal it ๐๐ป
#CSS
Radiento
a bento box radio group design with View Transition animations plus custom "squish" easing from Open Props ๐ค
โ grid layout
โ no abs positions
โ visual transition is an upgrade
โ respects reduced motion
โ keyboard still rocks
in Chromium 86 now:
1-click
#accessibility
color contrast correction for AA and AAA ratios ๐
Struggle to fix failing contrast ratios?
Tired of the guess and check?
@ChromeDevTools
has your back.
Here's a video of me fixing a few pesky ratio's with the new feature ๐
๐จ a 4 corner layered gradient by stacking 2 simple linear gradients and using a linear mask to blend them together!
1 red to cyan gradient
1 hotpink to rebeccapurple gradient
and a mask-image: linear-gradient(to bottom, transparent, black);
codepen
6 Different
#CSS
Centering Grid & Flex Layouts ๐
`place-items: center`
`place-content: center`
when used with..
`display: flex` vs `display: grid`
What's the difference?
What do they even do?!
I got ya ๐๐ค
Announcingโฆ ๐ฅ
A modern
#CSS
gradient and color picking tool for next-gen gradients:
- explore color spaces
- export modern and classic CSS
- explore gradient features
- share them
- learn rad tips & tricks
Chrome and Safari only (but not for long!)
๐ in Chrome Canary:
dynamic contextual flexbox alignment icons! Intent is to assist you by projecting a minimap of the alignment ๐บ
Let us know if these help!
Animate every element as it enters the viewport (not saying to do this lol) with just a few lines of CSS ๐
I love the โจnatural staggerโจ this effect has, since it's duration/length and intersection with the viewport, is on an item by item basis ๐ค
CSS "individual transforms"
in 2021 we'll see these in a lot more styles! Firefox has it, Safari tech preview has it, and Chrome's nearly finished.
value:
- composable transforms
- single transform access
- write less
read more in the spec
Wondering how sites like Github have nice dark form controls?
You gotta set the color-scheme!
โ enable from CSS (whole page or per selector)
โ enable from HTML (page can prepare early for your dark scheme)
lots more on -
You can use
#CSS
to tailor UX writing based on device capabilities ๐ค
Here I instruct the user to either hover or tap, depending on if the device can hover or not ๐๐ป
LET CSS PICK AN ACCESSIBLE COLOR!
`color-contrast()` will automatically pick a color that passes contrast ratios, just give it a list to choose from. aka: throw colors at it!
```
#css
body {
background: var(--blue2);
color: var(--onblue2);
}
```
Red won!
```
#css
color-contrast(black vs blue, red, green)
```
This function returns the color which contrasts the most with the 1st color.
โ ๏ธ LET CSS ENSURE YOU PASS CONTRAST SCORES โ ๏ธ
user in data saver mode?
skip the media, save loads!
```css
@media
(prefers-reduced-data: reduce) {
img, video {
display: none;
}
}
```
(Canary behind a flag only)
enjoy NICE page performance boosts and $$ data savings as the user is mostly browsing text. wins for all!
#CSS
trick - Bouncy Overscroll ๐ช
Flank a scroll snapping layout with unsnappables ๐ค
result:
as users scroll to an edge, it'll snap back to the nearest snappable with built-in inertia / timing
๐น try it
my
#CSS
typography for headers lately:
- unitless liquid line height
- wraps on wide/long (less legible!) headlines
- 1 liner liquid font size
color / spacing belong to the rest of the system, but I just tweak those values for my type system.
sandbox ๐
```
#css
-webkit-mask-image: linear-gradient(to right,
#0000
,
#000
,
#000
,
#0000
)
```
wrote that last night to give a horizontal scroller a nice "scroll hint" by masking it's edges; scroller edge fades
try it
Wanna change a parent with CSSโฝ
Check out `:has`
Getting prototyped in Chromium by
@igalia
๐, they believe they've "gathered enough information and data on this that we feel like we're ready to share it for wider review and discussion, productively"
New Post: I would say that I am unreasonably excited about this, but.. it doesn't seem unreasonable!
Today
@igalia
will file an intent to prototype :has() - here's a bunch of information on why/how/what this means. Thanks to
@eyeo
for sponsoring the work
1-Line Layouts by
@Una
โ10 modern CSS layout and sizing techniques that highlight just how robust and impactful a single-line of styling code can beโ - ๐ฆ
watch it ๐ผ
visit it ๐
my favorite 4 ๐๐
`accent-color: hotpink;` ๐
Chromium is prototyping the style feature for forms! I couldn't wait, so I went and tried it out in a custom build. Here it is!
hotpink checkboxes with 1 line of CSS ๐
CSS Spec
ChromeStatus
Use
#CSS
to customize HTML list bullets (and more!) in the upcoming Chromium 86 release (Canary or Beta today)
๐ individual && global selectors
li::marker {
color: var(--neon-pink);
}
li:first-child::marker {
font-size: 1ex;
}
Learn more ๐
TIL about the CSS media query `prefers-reduced-data`
๐๐ค
If users have data saver on:
- deliver smaller images or just a gradient
- smarter <picture> <source>'s
- more!?
proposal
spec
rad work
@hj_chen
! ๐
Gradient Border with Rounded Corners
just made this demo for someone, figured I'd share it here too:
1. transparent border to create the size and space
2. a border radius
3. a gradient filled to the border-box, a white layer on top in the padding-box
boxes are 2 lines of CSS now btw
```
#css
.box {
aspect-ratio: 1;
width: 100px;
}
```
set a width OR height, get a box
thx aspect-ratio ๐๐ป
(Chrome 88+, Safari TP, Firefox behind a flag)
caniuse -
โค๏ธ
#CSS
View Transitions
this API can do like anything!
even animate `display: none` ๐คฏ
this demo:
1. copies what you type into the `<pre>`
2. calls `document.startViewTransition()` if available
3. then pastes into a `<style>` tag!
animated local dev.
make focus a little more engaging
```css
@media
(prefers-reduced-motion: no-preference) {
:focus {
transition: outline-offset .25s ease;
outline-offset: 5px;
}
}
```
try it
new in Canary
@ChromeDevTools
:
Copy authored CSS
Another VisBug inspired feature ๐ Where VisBug can copy computed styles off any element, now DevTools can now copy authored styles off any element!
Both copy to the clipboard; aka lift & shift them wherever you want ๐๐ค
need a horizontal scrollview in
#CSS
?
here's some props to know!
`overflow`
what do you do when children are bigger than you?
iOS overflow: ๐
`scroll-behavior`
jump or animate to anchors
`overscroll-behavior`
when scrolling beyond this scrollview, allow or capture events
6 Different
#CSS
Centering Grid & Flex Layouts ๐
`place-items: center`
`place-content: center`
when used with..
`display: flex` vs `display: grid`
What's the difference?
What do they even do?!
I got ya ๐๐ค
Animates <table>
โ row.remove()
โ table.insertAdjacentHTML()
โค๏ธโ๐ฅ special animation like the table is crushing a row out of existence hehe
โ used devtools in the vid to slowmo the effect
viva View Transitions:
src on Codepen:
#CSS
`::first-line`
A dynamic and responsive pseudo selector that targets the first line of text.
p::first-line {
font-style: bold;
background: hotpink;
color: white;
}
See how ::first-line adapts to text wrapping, super cool!
Virtual Keyboard API ๐
"developers can use [virtual keyboards] to enable better customization of their webpage's content and experiences."
```js
navigator.virtualKeyboard.overlaysContent = true
```
```css
env(keyboard-inset-height)
```
learn more ๐
```JS
if (progress.value == '100' && progress.max == '100') {
// progress complete
}
```
```CSS
progress[value="100"][max="100"] {
/* progress complete */
}
```
While CSS has no if statements,
you can definitely use it similarly ๐๐ป