:root {
--primary-color: #3498db;
--font-size: 16px;
}
.button {
background-color: var(--primary-color);
font-size: var(--font-size);
}
document.documentElement.style.setProperty('--primary-color', '#e74c3c');
| 브라우저 | 접두사 |
|---|---|
| Chrome, Edge, Safari | -webkit- |
| Firefox | -moz- |
| Internet Explorer | -ms- |
| Opera (옛날 버전) | -o- |
.button {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-ms-border-radius: 10px;
border-radius: 10px;
}
벤더 프리픽스를 자동으로 추가해주는 도구
@supports (display: grid) {
.container {
display: grid;
}
}
//다중조건
@supports ((display: flex) or (display: grid)) {
.container {
display: flex;
}
}
//JavaScript에서 지원 여부 확인
if (CSS.supports("display", "grid")) {
console.log("Grid 지원됨!");
}
| 기능 | Polyfill 도구 |
|---|---|
| CSS Variables | css-vars-ponyfill |
| Flexbox | Flexibility |
| Grid | IE Grid Layout Polyfill |
| 스타일 시트 | 특징 |
|---|---|
| Reset.css | 모든 기본 스타일 제거 (완전히 초기화) |
| Normalize.css | 브라우저 간 기본 스타일을 "일관성 있게 유지" |
//Reset.css 사용 예제
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
//Normalize.css 사용 예제
html {
line-height: 1.15;
-webkit-text-size-adjust: 100%;
}
클래스 명명 규칙으로 유지보수성과 가독성을 높이는 방법
.block__element--modifier { }
| 개념 | 설명 |
|---|---|
| Block | 독립적인 요소 (ex: button) |
| Element | 블록 내의 하위 요소 (ex: button__icon) |
| Modifier | 특정 상태 (ex: button--disabled) |
.card { }
.card__title { }
.card__button { }
.card__button--active { }
순수 CSS 사용 (Bootstrap, Tailwind 등 없이 직접 스타일링)
미리 설계된 컴포넌트를 제공 (Bootstrap, Material UI 등)
클래스를 조합하여 스타일 적용 (Tailwind CSS 등)