使用 CSS 设置以 em 为单位的字体大小
cssweb developmentfront end technology更新于 2025/6/6 2:20:17
要以像素为单位设置字体大小,请使用 em 单位和 font-size 属性。
1em = 16px
示例
您可以尝试运行以下代码,以 em 为单位设置字体大小
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
/* 30px/16 = 1.875em */
font-size: 1.875em;
}
</style>
</head>
<body>
<h1>This is demo heading</h1>
<p>This is demo text.</p>
</body>
</html>
相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

