선택자
기본 선택자
*전체 — 모든 요소
div타입 — 모든
요소
.class클래스 — 해당 클래스를 가진 요소
#idID — 해당 id를 가진 요소
[attr]속성 — 속성이 있는 요소
[attr="val"]속성 값 일치
결합자
A B자손 (모든 깊이)
A > B직접 자식만
A + B인접 형제 (다음)
A ~ B일반 형제 (이후 모두)
가상 클래스
:hover요소 위에 마우스 올림
:focus요소에 포커스
:first-child부모의 첫 번째 자식
:nth-child(n)n번째 자식 (1부터, odd, even, 2n+1)
:not(sel)부정 — 매칭 제외
:has(sel)부모 선택자 (매칭 포함)
가상 요소
::before요소 앞에 콘텐츠 삽입
::after요소 뒤에 콘텐츠 삽입
::placeholder입력 placeholder 텍스트 스타일
::selection선택된 텍스트 스타일
박스 모델
박스 사이징
/* Include padding/border in width */ *, *::before, *::after { box-sizing: border-box; }
속성
margin테두리 바깥 공간
borderpadding 주변 테두리
padding테두리 안쪽 공간
width / height콘텐츠 크기
outlinemargin 바깥 링 (공간 없음)
단축 표기
margin: 10px; /* all sides */ margin: 10px 20px; /* vertical | horizontal */ margin: 10px 20px 30px; /* top | horiz | bottom */ margin: 10px 20px 30px 40px; /* T R B L */
Flexbox
컨테이너
.flex { display: flex; justify-content: center; /* main axis */ align-items: center; /* cross axis */ gap: 1rem; }
컨테이너 속성
flex-directionrow | column | row-reverse | column-reverse
flex-wrapnowrap | wrap | wrap-reverse
justify-contentflex-start | center | space-between | space-around | space-evenly
align-itemsstretch | center | flex-start | flex-end | baseline
align-content다중 줄 교차 축 정렬
gapflex 아이템 사이 공간
아이템 속성
flex: 1남은 공간 채우기
flex: 0 0 200px고정 너비, 늘림/줄임 없음
align-self한 아이템에 대해 align-items 재정의
order시각적 순서 변경 (기본값 0)
Grid
컨테이너
.grid { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: auto 1fr auto; gap: 1rem; }
컨테이너 속성
grid-template-columns열 트랙 정의: 1fr 2fr, repeat(3, 1fr)
grid-template-rows행 트랙 정의
grid-template-areas명명된 영역: "header header" "nav main"
gap행 및 열 간격
justify-items인라인 방향으로 아이템 정렬 (수평)
align-items블록 방향으로 아이템 정렬 (수직)
아이템 배치
.item { grid-column: 1 / 3; /* span cols 1-2 */ grid-row: 1 / -1; /* span all rows */ grid-area: header; /* named area */ }
타이포그래피
폰트 속성
font-family폰트 스택: 'Inter', sans-serif
font-size크기: 1rem, 16px, clamp(1rem, 2vw, 2rem)
font-weightnormal (400) | bold (700) | 100-900
font-stylenormal | italic | oblique
line-height줄 간격: 1.5 (단위 없음 권장)
letter-spacing자간: 0.05em
텍스트 속성
text-alignleft | center | right | justify
text-decorationnone | underline | line-through
text-transformuppercase | lowercase | capitalize
text-overflowellipsis (overflow: hidden과 함께)
white-spacenowrap | pre | pre-wrap
word-breakbreak-all | break-word
색상 & 배경
색상 형식
color: #ff6600; /* hex */ color: rgb(255, 102, 0); /* rgb */ color: hsl(24, 100%, 50%); /* hsl */ color: oklch(70% 0.15 50); /* oklch */
배경 속성
background-color단색 채우기: #f0f0f0
background-imageurl(img.jpg) 또는 그라디언트
background-sizecover | contain | 100px 200px
background-positioncenter | top right | 50% 50%
background-repeatno-repeat | repeat-x | repeat-y
그라디언트
background: linear-gradient(to right, #f00, #00f); background: radial-gradient(circle, #fff, #000); background: conic-gradient(red, yellow, green);
트랜지션 & 애니메이션
트랜지션
.btn { transition: background 0.3s ease, transform 0.2s; } .btn:hover { background: #0056b3; transform: scale(1.05); }
트랜지션 속성
transition-property애니메이션할 속성
transition-duration길이: 0.3s, 300ms
transition-timing-functionease | linear | ease-in-out | cubic-bezier()
transition-delay시작 전 대기 시간
키프레임 애니메이션
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } .icon { animation: spin 1s linear infinite; }
애니메이션 속성
animation-name@keyframes 이름 참조
animation-duration한 주기의 길이
animation-iteration-count1 | 3 | infinite
animation-directionnormal | alternate | reverse
animation-fill-modeforwards | backwards | both
반응형 디자인
미디어 쿼리
@media (max-width: 768px) { .sidebar { display: none; } } @media (prefers-color-scheme: dark) { body { background: #1a1a1a; color: #eee; } }
일반 브레이크포인트
max-width: 480px모바일 폰
max-width: 768px태블릿
max-width: 1024px소형 노트북
max-width: 1280px데스크톱
뷰포트 단위
vw / vh뷰포트 너비 / 높이의 %
dvh동적 뷰포트 높이 (모바일 안전)
svh / lvh소형 / 대형 뷰포트 높이
cqi컨테이너 쿼리 인라인 크기
컨테이너 쿼리
.card-wrapper { container-type: inline-size; } @container (min-width: 400px) { .card { flex-direction: row; } }
포지셔닝
position 값
static기본값 — 일반 문서 흐름
relative일반 위치에서 오프셋; 공간 유지
absolute가장 가까운 위치 지정 조상에 배치
fixed뷰포트에 배치; 스크롤 시 고정
sticky스크롤에 따라 relative/fixed 전환
중앙 정렬 패턴
/* Flex center */ display: flex; justify-content: center; align-items: center; /* Grid center */ display: grid; place-items: center;
스태킹
z-index스택 순서 (높을수록 위); position 필요
isolation: isolate새 스태킹 컨텍스트 생성
커스텀 속성
정의 & 사용
:root { --color-primary: #3b82f6; --spacing-md: 1rem; } .btn { background: var(--color-primary); padding: var(--spacing-md); }
대체값
color: var(--accent, #ff6600); /* uses #ff6600 if --accent is not defined */
동적 테마
[data-theme="dark"] { --bg: #1a1a2e; --text: #e0e0e0; } body { background: var(--bg); color: var(--text); }