[!NOTE]
postcss-cssnexthas been deprecated in favor ofpostcss-preset-env. This cheat sheet serves as a reference for legacy projects utilizing cssnext syntaxes.
CSS Custom Properties (Variables)
:root {
--primary-color: #3b82f6;
--spacing-base: 1rem;
}
.button {
background: var(--primary-color);
padding: var(--spacing-base);
}
Custom Selectors & Nesting
Custom Selectors
@custom-selector :--heading h1, h2, h3, h4, h5, h6;
:--heading {
margin-top: 0;
font-weight: 700;
}
Native CSS Nesting
.card {
padding: 1rem;
& .title {
font-size: 1.25rem;
}
&:hover {
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
}
Custom Media Queries
@custom-media --small-viewport (max-width: 30em);
@custom-media --large-viewport (min-width: 60em);
@media (--small-viewport) {
body {
font-size: 14px;
}
}
Functional Color Functions
a {
/* Relative adjustments */
color: color(var(--primary-color) alpha(-20%));
color: color(red tint(20%)); /* Lighten */
color: color(blue shade(30%)); /* Darken */
/* Grayscale shortcuts */
background: gray(50); /* rgb(50, 50, 50) */
background: gray(80%); /* 80% lightness */
}