diff --git a/snippets/css-not-selector-shortcut.md b/snippets/css-not-selector-shortcut.md index 66782be75..883edab2a 100644 --- a/snippets/css-not-selector-shortcut.md +++ b/snippets/css-not-selector-shortcut.md @@ -1,46 +1,95 @@ ### CSS :not selector shortcut -Lots of code just to space each item evenly, except for the last one is just one great example for the `:not` psuedo selector. +The `:not` psuedo selector is perfect for styling a group of elements, and leaving the last (or specified) element unstyled without all the lines of code. #### HTML ```html - +
``` #### CSS ```css +li { + display: inline-block; + + list-style-type: none; + margin: 0; + padding: .25em 1em; +} +.css-not-selector-shortcut a { + text-decoration:none; + color: #111111; +} + +.css-not-selector-shortcut li:not(:last-child) { + border-right: 1px solid #666666; +} ``` #### Demo - - - - #### Explanation - +1. Instead of putting on the border and then taking it off: +```css +.css-not-selector-shortcut li { + border-right: 1px solid #666666; +} + +.css-not-selector-shortcut li:last-child { + border-right: none; +} +``` + +2. Use the `:not` psuedo selector to save a few lines: +```css +.css-not-selector-shortcut li:not(:last-child) { + border-right: 1px solid #666666; +} +``` #### Browser support - - ✅ No caveats. - - * https://caniuse.com/#feat=css-sel3 - +