网页字体相关的CSS属性主要用于设置和控制文本的字体样式。以下是一些常用的CSS属性及其解释:
Arial, Times New Roman, Verdana 等。@font-face 规则引入自定义字体文件。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Font Example</title>
<style>
body {
font-family: 'Arial', sans-serif;
font-size: 16px;
color: #333;
}
h1 {
font-family: 'Times New Roman', serif;
font-size: 24px;
font-weight: bold;
color: #f00;
}
.highlight {
font-style: italic;
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Welcome to Our Website</h1>
<p>This is a <span class="highlight">sample text</span> to demonstrate font properties.</p>
</body>
</html>@font-face {
font-family: 'CustomFont';
src: url('CustomFont.woff2') format('woff2'),
url('CustomFont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
body {
font-family: 'CustomFont', Arial, sans-serif;
}font-display 属性优化加载体验。@font-face {
font-family: 'CustomFont';
src: url('CustomFont.woff2') format('woff2'),
url('CustomFont.woff') format('woff');
font-weight: normal;
font-style: normal;
font-display: swap;
}通过以上方法,可以有效解决字体在不同设备上的显示问题以及加载缓慢的问题。