cheatsheets/cssnext.md

171 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

2017-03-04 16:22:29 +00:00
---
title: cssnext
2017-08-29 13:38:06 +00:00
category: CSS
2020-07-04 13:33:09 +00:00
updated: 2017-10-30
tags: [Featurable]
2017-08-29 21:53:45 +00:00
weight: -3
2017-03-04 16:22:29 +00:00
---
2017-08-29 13:38:06 +00:00
### Variables
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
2017-03-04 16:22:29 +00:00
:root {
--text-color: #30333a;
}
2017-08-29 13:38:06 +00:00
```
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
2017-03-04 16:22:29 +00:00
body {
background: var(--text-color);
background: color(var(--text-color) shade(30%));
}
```
2017-03-04 16:26:25 +00:00
### Colors
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
2017-03-04 16:22:29 +00:00
a {
/* Adjustments */
color: color(red alpha(-10%));
color: color(red tint(-10%)); /* lighten */
color: color(red shade(-10%)); /* darken */
/* Absolute */
color: color(red alpha(50%));
color: color(red hue(225));
color: color(red saturation(100%));
color: color(red lightness(50%));
color: gray(33); /* rgb(33, 33, 33) */
color: gray(33%); /* rgb(84, 84, 84) */
color: gray(33%, 50%); /* rgba(84, 84, 84, 0.5) */
color: #0000ff80; /* rgba(0, 0, 255, 0.5) */
color: hwb(90, 0%, 0%, 0.5); /* like hsl() but easier for humans */
2017-03-04 18:38:14 +00:00
color: hsl(90deg 90% 70%); /* hsl(180, 90%, 70%) -- supports deg */
2017-03-04 16:22:29 +00:00
color: hsl(90deg 90% 70% / 30%); /* hsla(180, 90%, 70%, 0.3) */
color: rgb(30 60 90 / 30%); /* rgba(30, 60, 90, 0.3) */
}
```
2017-08-29 13:38:06 +00:00
Also see [colorme.io](http://colorme.io/).
2017-03-04 16:26:25 +00:00
### Mixins
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
2017-03-04 16:22:29 +00:00
:root {
--centered: {
display: flex;
align-items: center;
justify-content: center;
};
}
.centered {
@apply --centered;
}
```
2017-03-04 16:26:25 +00:00
Selectors
---------
2017-03-04 16:22:29 +00:00
2017-03-04 16:26:25 +00:00
### Nesting
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
2017-03-04 16:26:25 +00:00
.class-name {
2017-08-29 13:38:06 +00:00
& .nesting { ··· } /* direct nesting starts with & */
@nest span & { ··· } /* complex nesting */
@media (min-width: 30em) { ··· }
2017-03-04 16:26:25 +00:00
}
2017-03-04 16:22:29 +00:00
```
2017-03-04 16:26:25 +00:00
### Custom selectors
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
@custom-selector :--button input[type='submit'], input[type='button'];
2017-03-04 16:22:29 +00:00
@custom-selector :--enter :hover, :focus;
2017-08-29 13:38:06 +00:00
```
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
:--button { ··· }
:--button:--enter { ··· }
2017-03-04 16:22:29 +00:00
```
2017-08-29 13:38:06 +00:00
{: .-setup}
2017-03-04 16:22:29 +00:00
2017-03-04 16:26:25 +00:00
### Future selectors
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
:any-link { ··· } /* :link, :visited */
p:matches(.a, .b) { ··· } /* p.a, p.b */
p:not(.a, .b) { ··· } /* p:not(.a), p:not(.b) */
a::before { ··· } /* a:before -- for IE compatibility */
[frame=hsides i] { ··· } /* [frame=hsides] -- but case insensitive */
2017-03-04 16:22:29 +00:00
```
2017-03-04 16:26:25 +00:00
Media queries
-------------
### Custom media queries
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
2017-03-04 16:26:25 +00:00
@custom-media --viewport-medium (width <= 50rem);
2017-08-29 13:38:06 +00:00
```
```scss
@media (--viewport-medium) { ··· }
2017-03-04 16:26:25 +00:00
```
2017-03-04 16:22:29 +00:00
2017-03-04 16:26:25 +00:00
### Media query ranges
2017-08-29 13:38:06 +00:00
```scss
@media (width >= 500px) { ··· } /* (min-width: 500px) */
2017-03-04 16:22:29 +00:00
```
2017-03-04 16:26:25 +00:00
Properties
----------
### Property fallbacks
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
2017-03-04 16:26:25 +00:00
/* font-feature-settings fallback */
h2 { font-variant-caps: small-caps; }
table { font-variant-numeric: lining-nums; }
2017-08-29 13:38:06 +00:00
```
2017-03-04 16:26:25 +00:00
2017-08-29 13:38:06 +00:00
```scss
div { filter: blur(4px); } /* svg filter fallback */
div { overflow-wrap: break-word; } /* word-wrap fallback */
2017-03-04 16:22:29 +00:00
```
2017-03-04 16:26:25 +00:00
### Autoprefixing
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
2017-03-04 16:22:29 +00:00
div {
display: flex;
}
2017-08-29 13:38:06 +00:00
```
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
```scss
2017-03-04 16:22:29 +00:00
/*
* display: -webkit-box;
* display: -ms-flexbox;
* display: flex;
*/
```
2017-03-04 16:26:25 +00:00
### Reset
2017-08-29 13:38:06 +00:00
```scss
2017-03-04 16:26:25 +00:00
div {
all: initial;
}
```
2017-08-29 13:38:06 +00:00
Sets animation, background, margin, padding, and so on.
2017-03-04 16:26:25 +00:00
2017-03-04 16:22:29 +00:00
## References
2017-08-29 13:38:06 +00:00
{: .-one-column}
2017-03-04 16:22:29 +00:00
2017-08-29 13:38:06 +00:00
- Based on cssnext 2.9.0.
- <http://cssnext.io/features/>