[!NOTE] postcss-cssnext는 postcss-preset-env로 대체되어 더 이상 유지보수되지 않습니다. 본 문서는 cssnext 문법을 사용하는 기존 프로젝트 참조용입니다.
CSS 커스텀 프로퍼티 (변수)
:root {
--primary-color: #3b82f6;
--spacing-base: 1rem;
}
.button {
background: var(--primary-color);
padding: var(--spacing-base);
}
사용자 정의 선택자 및 네스팅 (Nesting)
사용자 정의 선택자
@custom-selector :--heading h1, h2, h3, h4, h5, h6;
:--heading {
margin-top: 0;
font-weight: 700;
}
네이티브 CSS 네스팅
.card {
padding: 1rem;
& .title {
font-size: 1.25rem;
}
&:hover {
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
}
사용자 정의 미디어 쿼리
@custom-media --small-viewport (max-width: 30em);
@custom-media --large-viewport (min-width: 60em);
@media (--small-viewport) {
body {
font-size: 14px;
}
}
색상 조작 함수
a {
/* 상대적 투명도 조절 */
color: color(var(--primary-color) alpha(-20%));
color: color(red tint(20%)); /* 색상 밝게 조절 */
color: color(blue shade(30%)); /* 색상 어둡게 조절 */
/* 고정값 기반 그레이스케일 */
background: gray(50);
/* 밝기 백분율 기반 그레이스케일 */
background: gray(80%);
}