使用外部CSS文件,将所有的CSS样式集中在一个或多个外部文件中,然后在HTML文件中通过标签引入。便于维护和更新。可以在多个页面之间共享样式。提高页面加载速度,因为浏览器可以缓存CSS文件。
示例:
<!-- HTML文件 -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<a href="https://example.com" class="link">Example Link</a>
</body>
</html>
/* styles.css文件 */
.link {
color: blue;
text-decoration: none;
}
.link:hover {
text-decoration: underline;
}