CSS(层叠样式表,Cascading Style Sheets)是一种用来描述HTML或XML(包括SVG、XHTML等)文档样式的样式表语言。它允许开发者通过定义一系列的样式规则来控制页面元素的布局、颜色、字体等视觉表现。
<link>
标签引用。<head>
部分,使用<style>
标签包裹。style
属性中编写CSS代码。<!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;
color: #333;
}
h1 {
font-size: 2em;
color: #f00;
}
p {
line-height: 1.6;
}
</style>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a paragraph with some text. CSS is used to style this text.</p>
</body>
</html>
原因:不同浏览器对CSS的支持程度和默认样式可能有所不同。
解决方法:
font-family: Arial, sans-serif;
,确保在无特定字体时使用通用字体。@font-face {
font-family: 'MyCustomFont';
src: url('path/to/font.woff2') format('woff2'),
url('path/to/font.woff') format('woff');
}
通过以上方法,可以有效解决字体样式在不同浏览器中显示不一致的问题。