단축 속성을 사용하여 글꼴 속성 결합
이 단계에서는 CSS font 단축 속성을 사용하여 여러 폰트 관련 속성을 단일하고 간결한 선언으로 결합하는 방법을 배웁니다. 이 접근 방식은 CSS 를 더 읽기 쉽고 효율적으로 만듭니다.
typography.html 파일을 열고 다음 CSS 로 <style> 섹션을 업데이트합니다.
<style>
h1 {
font:
bold italic 36px Arial,
sans-serif;
}
h2 {
font:
600 24px "Times New Roman",
serif;
}
p {
font:
normal 16px/1.6 Verdana,
sans-serif;
}
.highlight {
font:
bold italic 16px Verdana,
sans-serif;
}
</style>
단축 속성 font 구문을 자세히 살펴보겠습니다.
-
기본 구문: font: [font-style] [font-weight] [font-size] [line-height] [font-family]
- 순서가 중요합니다!
- 모든 값을 필수로 지정할 필요는 없습니다.
-
일반적인 단축 패턴:
font: style weight size family
font: size/line-height family
font: weight size family
단축 속성을 보여주도록 HTML 을 수정합니다.
<body>
<h1>Main Heading (Shorthand)</h1>
<h2>Subheading (Compact Syntax)</h2>
<p>
Paragraph with line height. <span class="highlight">Highlighted text</span>.
</p>
</body>
브라우저에서의 예시 출력:
[다음을 보여주는 페이지:
- 굵고 기울임꼴 스타일의 메인 제목
- 간결한 폰트 선언의 부제목
- 통합된 줄 간격의 단락]