CSS(Cascading Style Sheets,层叠样式表)是一种用来描述HTML或XML(包括SVG、MathML等各种XML方言)文档样式的样式表语言。设置字体样式是CSS中最基本的用法之一,可以通过多种属性来控制字体的外观。
style
属性。<head>
部分使用<style>
标签。<link>
标签链接到一个外部的CSS文件。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS Font Styling Example</title>
<style>
body {
font-family: Arial, sans-serif;
font-size: 16px;
line-height: 1.6;
}
h1 {
font-family: 'Times New Roman', serif;
font-size: 24px;
font-weight: bold;
text-decoration: underline;
}
p {
font-style: italic;
}
</style>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is an example of how to style text using CSS.</p>
</body>
</html>
em
、rem
)而不是绝对单位(如px
),以确保在不同设备和屏幕尺寸上的一致性。@import
导入字体,因为这可能导致字体在页面加载时出现闪烁。通过上述方法,你可以有效地设置和控制网页中的字体样式,以提升用户体验和网站的整体美观度。
领取专属 10元无门槛券
手把手带您无忧上云