Skip to content

Commit 5d0db6c

Browse files
committed
Add Conditional Styling For Unsupported CSS Features as a css til
1 parent 16308f6 commit 5d0db6c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket.
99

1010
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
1111

12-
_887 TILs and counting..._
12+
_888 TILs and counting..._
1313

1414
---
1515

@@ -99,6 +99,7 @@ _887 TILs and counting..._
9999
- [Apply Styles To The Last Child Of A Specific Type](css/apply-styles-to-the-last-child-of-a-specific-type.md)
100100
- [Change The Orientation Of An Image](css/change-the-orientation-of-an-image.md)
101101
- [Circular Icons With A Massive Border Radius](css/circular-icons-with-a-massive-border-radius.md)
102+
- [Conditional Styling For Unsupported CSS Features](css/conditional-styling-for-unsupported-css-features.md)
102103
- [Create A Pulsing Background With CSS Animation](css/create-a-pulsing-background-with-css-animation.md)
103104
- [Dry Up SCSS With Mixins](css/dry-up-scss-with-mixins.md)
104105
- [Give Elements The Same Width With Flexbox](css/give-elements-the-same-width-with-flexbox.md)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Conditional Styling For Unsupported CSS Features
2+
3+
As much as possible, you should aim to use CSS features that have broad browser
4+
support. Sometimes browsers lag behind or you'd like to take advantage of a
5+
draft feature in browsers that support it.
6+
7+
For these situations, you can provide conditional styling using the
8+
[`@supports`
9+
at-rule](https://developer.mozilla.org/en-US/docs/Web/CSS/@supports).
10+
11+
Here is an example of conditionally using `display: grid` if it is supported:
12+
13+
```css
14+
@supports (display: grid) {
15+
div {
16+
display: grid;
17+
}
18+
}
19+
```
20+
21+
In [this
22+
article](https://24ways.org/2019/zs-still-not-dead-baby-zs-still-not-dead/)
23+
there is an example of using `background-blend-mode` and falling back to
24+
`background-image` if it isn't supported.
25+
26+
```css
27+
@supports not (background-blend-mode: normal) {
28+
body {
29+
background-image: url(fallback.png);
30+
}
31+
}
32+
```

0 commit comments

Comments
 (0)