CSS(层叠样式表)是一种用于描述HTML或XML(包括SVG、MathML等各种XML方言)文档样式的样式表语言。字体样式是CSS中用于设置文本外观的属性集合,包括字体家族、大小、粗细、样式(如斜体)、颜色等。
font-family
。font-size
。font-weight
。font-style
。line-height
。text-decoration
。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Font Styling</title>
<style>
body {
font-family: 'Arial', sans-serif;
font-size: 16px;
line-height: 1.5;
color: #333;
}
h1 {
font-family: 'Times New Roman', serif;
font-size: 24px;
font-weight: bold;
color: #007BFF;
}
.italic {
font-style: italic;
}
.underline {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Welcome to Our Website</h1>
<p>This is a sample paragraph with <span class="italic">italic</span> and <span class="underline">underlined</span> text.</p>
</body>
</html>
问题1:字体在不同设备上显示不一致
sans-serif
或 serif
),或者通过 @font-face
规则引入自定义字体。@font-face {
font-family: 'MyCustomFont';
src: url('path/to/font.woff2') format('woff2'),
url('path/to/font.woff') format('woff');
}
问题2:文本重叠
line-height
和元素间距,确保文本之间有足够的空间。p {
line-height: 1.6;
margin-bottom: 10px;
}
通过以上方法,可以有效解决CSS字体样式中的常见问题,提升网页的视觉效果和用户体验。