字体大小是指字符相对于文本基线的高度。较大的字体通常用于标题或标题以吸引注意力,而较小的字体则适用于正文文本或标题以确保可读性。
font-size 属性会影响元素文本的大小。
可能的值
绝对大小关键字:这些值基于 uesr 的字体大小(中等)的默认大小。它包括:
- xx-small
- x-small
- small
- medium
- large
- large
- x-large
- xx-large
- xxx-large
相对大小关键字:这些值相对于父元素的字体大小而言相对较大或较小。它包括:
- larger
- smaller
<length>:这些是预定义的正值<length>值。它包括 em、ex、rem、px、in 等。
<percentage>:相对于父元素的字体大小的正值 <percentage>。
math:它是数学元素的 font-size 相对于父元素的 font-size 的计算值。
适用于
所有 HTML 元素。
DOM 语法
object.style.fontSize = "12pt";
CSS font-size - 基本示例
下面是一个示例:
<html>
<head>
</head>
<body>
<p style="font-size: large;">Font-size is large.</p>
<p style="font-size: medium;">Font-size is medium.</p>
<p style="font-size: small;">Font-size is small.</p>
<p style="font-size: smaller;">Font-size is smaller.</p>
<p style="font-size: xx-small;">Font-size is xx-small.</p>
<p style="font-size: 30px;">Font-size is 30pixels.</p>
<p style="font-size: 50%;">Font-size is 50%.</p>
<p style="font-size: 5vmin;">Font-size is 5vmin.</p>
</body>
</html>