CSS 中的相对长度单位
cssweb developmentfront end technology更新于 2024/12/10 12:28:17
CSS 中的相对长度单位用于指定相对于另一个长度属性的长度。
| Sr.No | Unit &说明 |
|---|---|
| 1 | em 相对于元素的字体大小,例如 4em 表示当前字体大小的 4 倍。 |
| 2 | ex 相对于当前字体的 x 高度 |
| 3 | ch 相对于 0 的宽度 |
| 4 | rem 相对于根元素的字体大小 |
| 5 | vw 相对于视口宽度的 1%* |
| 6 | vh 相对于视口高度的 1%* |
| 7 | vmin 相对于视口较小尺寸的 1%* |
| 8 | vmax 相对于视口较大尺寸的 1%* |
| 9 | % 相对于父级元素 |
示例
让我们看一个使用相对长度单位的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
.demo {
text-decoration: overline underline;
text-decoration-color: blue;
font-size: 1.4em;
}
</style>
</head>
<body>
<h1>Details</h1>
<p class="demo">Examination Center near ABC College.</p>
<p class="demo2">Exam begins at 9AM.</p>
</body>
</html>
输出

示例
现在让我们看另一个例子 −
<!DOCTYPE html>
<html>
<head>
<style>
.demo {
text-decoration: overline underline;
text-decoration-color: blue;
font-size: 4ch;
}
</style>
</head>
<body>
<h1>Details</h1>
<p class="demo">Examination Center near ABC College.</p>
<p class="demo2">Exam begins at 9AM.</p>
</body>
</html>
输出

相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

