--- title: 클래스 선택자 slug: Web/CSS/Class_selectors tags: - CSS - Reference - Selectors translation_of: Web/CSS/Class_selectors --- <div>{{CSSRef}}</div> <p><a href="/ko/docs/Web/CSS">CSS</a> <strong>클래스 선택자</strong>는 요소의 {{htmlattrxref("class")}} 특성에 기반해 요소를 선택합니다.</p> <pre class="brush: css no-line-numbers">/* All elements with class="spacious" */ .spacious { margin: 2em; } /* All <li> elements with class="spacious" */ li.spacious { margin: 2em; } /* All <li> elements with a class list that includes both "spacious" and "elegant" */ /* For example, class="elegant retro spacious" */ li.spacious.elegant { margin: 2em; } </pre> <h2 id="구문">구문</h2> <pre class="syntaxbox">.class_name { <em>style properties</em> }</pre> <p>위의 구문은 <a href="/ko/docs/Web/CSS/Attribute_selectors">특성 선택자</a>를 사용한 다음 구문과 동일합니다.</p> <pre class="syntaxbox">[class~=class_name] { <em>style properties</em> }</pre> <h2 id="예제">예제</h2> <h3 id="CSS">CSS</h3> <pre class="brush: css">.red { color: #f33; } .yellow-bg { background: #ffa; } .fancy { font-weight: bold; text-shadow: 4px 4px 3px #77f; } </pre> <h3 id="HTML">HTML</h3> <pre class="brush: html"><p class="red">빨간 글자색의 문단입니다.</p> <p class="red yellow-bg">빨간 글자색과 노란 배경의 문단입니다.</p> <p class="red fancy">빨간 글자색과 "멋진" 스타일을 가진 문단입니다.</p> <p>이건 그냥 문단이에요.</p> </pre> <h3 id="결과">결과</h3> <p>{{EmbedLiveSample('예제')}}</p> <h2 id="명세">명세</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS4 Selectors', '#class-html', 'class selectors')}}</td> <td>{{Spec2('CSS4 Selectors')}}</td> <td>No changes</td> </tr> <tr> <td>{{SpecName('CSS3 Selectors', '#class-html', 'class selectors')}}</td> <td>{{Spec2('CSS3 Selectors')}}</td> <td></td> </tr> <tr> <td>{{SpecName('CSS2.1', 'selector.html#class-html', 'child selectors')}}</td> <td>{{Spec2('CSS2.1')}}</td> <td></td> </tr> <tr> <td>{{SpecName('CSS1', '#class-as-selector', 'child selectors')}}</td> <td>{{Spec2('CSS1')}}</td> <td>Initial definition</td> </tr> </tbody> </table> <h2 id="브라우저_호환성">브라우저 호환성</h2> <p>{{Compat("css.selectors.class")}}</p>