Skip to content

Commit 28d8cf2

Browse files
Add :is() pseudo-class tip
1 parent 75c9c70 commit 28d8cf2

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

README.md

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ A collection of tips to help take your CSS skills pro.
4545
1. [Use Pointer Events to Control Mouse Events](#use-pointer-events-to-control-mouse-events)
4646
1. [Set `display: none` on Line Breaks Used as Spacing](#set-display-none-on-line-breaks-used-as-spacing)
4747
1. [Use `:empty` to Hide Empty HTML Elements](#use-empty-to-hide-empty-html-elements)
48+
1. [Control Specificity Better With `:is()`](#control-specificity-better-with-is)
4849

4950

5051
### Use a CSS Reset
@@ -63,7 +64,7 @@ CSS resets help enforce style consistency across different browsers with a clean
6364

6465
Now elements will be stripped of margins and padding, and `box-sizing` lets you manage layouts with the CSS box model.
6566

66-
#### [Demo](http://codepen.io/AllThingsSmitty/pen/kkrkLL)
67+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/kkrkLL)
6768

6869
**Note:** If you follow the [Inherit `box-sizing`](#inherit-box-sizing) tip below you might opt to not include the `box-sizing` property in your CSS reset.
6970

@@ -151,7 +152,7 @@ Instead of putting on the border...
151152

152153
Here, the CSS selector is read as a human would describe it.
153154

154-
#### [Demo](http://codepen.io/AllThingsSmitty/pen/LkymvO)
155+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/LkymvO)
155156

156157
<sup>[back to table of contents](#table-of-contents)</sup>
157158

@@ -194,7 +195,7 @@ body {
194195

195196
This way textual elements can inherit from `body` easily.
196197

197-
#### [Demo](http://codepen.io/AllThingsSmitty/pen/VjbdYd)
198+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/VjbdYd)
198199

199200
<sup>[back to table of contents](#table-of-contents)</sup>
200201

@@ -232,10 +233,7 @@ body {
232233
}
233234

234235
body {
235-
-webkit-align-items: center;
236-
-ms-flex-align: center;
237236
align-items: center;
238-
display: -webkit-flex;
239237
display: flex;
240238
}
241239
```
@@ -256,7 +254,7 @@ Want to center something else? Vertically, horizontally...anything, anytime, any
256254

257255
**Note:** Watch for some [buggy behavior](https://github.com/philipwalton/flexbugs#3-min-height-on-a-flex-container-wont-apply-to-its-flex-items) with flexbox in IE11.
258256

259-
#### [Demo](http://codepen.io/AllThingsSmitty/pen/GqmGqZ)
257+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/GqmGqZ)
260258

261259
<sup>[back to table of contents](#table-of-contents)</sup>
262260

@@ -302,7 +300,7 @@ li:not(:nth-child(-n+3)) {
302300
}
303301
```
304302

305-
#### [Demo](http://codepen.io/AllThingsSmitty/pen/WxjKZp)
303+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/WxjKZp)
306304

307305
<sup>[back to table of contents](#table-of-contents)</sup>
308306

@@ -344,7 +342,7 @@ In this example, all elements in the flow of the document that follow other elem
344342

345343
For more on the "lobotomized owl" selector, read [Heydon Pickering's post](http://alistapart.com/article/axiomatic-css-and-lobotomized-owls) on *A List Apart*.
346344

347-
#### [Demo](http://codepen.io/AllThingsSmitty/pen/grRvWq)
345+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/grRvWq)
348346

349347
<sup>[back to table of contents](#table-of-contents)</sup>
350348

@@ -383,7 +381,7 @@ Tables can be a pain to work with. Try using `table-layout: fixed` to keep cells
383381

384382
Pain-free table layouts.
385383

386-
#### [Demo](http://codepen.io/AllThingsSmitty/pen/jALALm)
384+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/jALALm)
387385

388386
<sup>[back to table of contents](#table-of-contents)</sup>
389387

@@ -422,7 +420,7 @@ That's pretty convenient.
422420

423421
**Note:** This tip may not be ideal for accessibility, specifically screen readers. And copy/paste from the browser doesn't work with CSS-generated content. Proceed with caution.
424422

425-
#### [Demo](http://codepen.io/AllThingsSmitty/pen/zBzXRx)
423+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/zBzXRx)
426424

427425
<sup>[back to table of contents](#table-of-contents)</sup>
428426

@@ -466,7 +464,7 @@ To create a box with an intrinsic ratio, all you need to do is apply top or bott
466464

467465
Using 20% for padding makes the height of the box equal to 20% of its width. No matter the width of the viewport, the child div will keep its aspect ratio (100% / 20% = 5:1).
468466

469-
#### [Demo](http://codepen.io/AllThingsSmitty/pen/jALZvE)
467+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/jALZvE)
470468

471469
<sup>[back to table of contents](#table-of-contents)</sup>
472470

@@ -573,7 +571,7 @@ body {
573571
}
574572
```
575573

576-
#### [Demo](http://codepen.io/AllThingsSmitty/pen/XKgOkR)
574+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/XKgOkR)
577575

578576
<sup>[back to table of contents](#table-of-contents)</sup>
579577

@@ -640,6 +638,34 @@ If you have HTML elements that are empty, i.e., the content has yet to be set ei
640638
<sup>[back to table of contents](#table-of-contents)</sup>
641639

642640

641+
### Control Specificity Better with `:is()`
642+
643+
The `:is()` pseudo-class is used to target multiple selectors at onece, reducing redundancy and enhancing code readability. This is incredibly useful for writing large selectors in a more compact form.
644+
645+
```css
646+
:is(section, article, aside, nav) :is(h1, h2, h3, h4, h5, h6) {
647+
color: green;
648+
}
649+
```
650+
651+
The above ruleset is equivalent to the following number selector rules...
652+
653+
```css
654+
section h1, section h2, section h3, section h4, section h5, section h6,
655+
article h1, article h2, article h3, article h4, article h5, article h6,
656+
aside h1, aside h2, aside h3, aside h4, aside h5, aside h6,
657+
nav h1, nav h2, nav h3, nav h4, nav h5, nav h6 {
658+
color: green;
659+
}
660+
```
661+
662+
#### [Demo](https://codepen.io/AllThingsSmitty/pen/rNRVxdx)
663+
664+
**Note:** The `:is()` pseudo-class isn't supported in IE11.
665+
666+
<sup>[back to table of contents](#table-of-contents)</sup>
667+
668+
643669
## Support
644670

645671
Current versions of Chrome, Firefox, Safari, Opera, Edge, and IE11.

0 commit comments

Comments
 (0)