添加字体样式和粗细
在这一步中,你将学习如何使用字体样式(font style)和粗细(font weight)通过 CSS 为文本添加强调和变化。这些属性有助于创建视觉层次结构,并提升排版的整体设计效果。
打开 typography.html
文件,并使用以下 CSS 更新 <style>
部分:
<style>
h1 {
font-family: Arial, sans-serif;
font-size: 36px;
font-style: italic;
font-weight: bold;
}
h2 {
font-family: "Times New Roman", serif;
font-size: 24px;
font-style: normal;
font-weight: 600;
}
p {
font-family: Verdana, sans-serif;
font-size: 16px;
font-style: normal;
font-weight: normal;
}
.highlight {
font-style: italic;
font-weight: bold;
}
</style>
让我们探讨一下关键概念:
-
字体样式(Font Style):
normal
:标准文本外观
italic
:斜体文本
oblique
:类似于斜体,但不常见
-
字体粗细(Font Weight):
normal
:常规文本(400)
bold
:更粗、更突出的文本(700)
- 数值:100-900(以 100 为增量)
修改你的 HTML 以展示这些属性:
<body>
<h1>主标题(斜体和粗体)</h1>
<h2>副标题(半粗体)</h2>
<p>
常规段落文本。
<span class="highlight">这段文本被高亮显示</span>。
</p>
</body>
在浏览器中的示例输出:
[一个页面显示:
- 主标题为斜体和粗体
- 副标题为半粗体
- 包含高亮显示的段落文本]