天天看点

Style fontSize 属性

Style 对象

定义和用法

fontSize 属性设置或返回文本的字体尺寸。

语法

设置 fontSize 属性:

Object.style.fontSize="value|inherit"

返回 fontSize 属性:

Object.style.fontSize

描述

xx-small

x-small

small

medium

large

x-large

xx-large

把字体的尺寸设置为不同的固定尺寸,从 xx-small 到 xx-large。
smaller 把字体尺寸减小一个相对单位。
larger 把字体尺寸增大一个相对单位。
length 使用 px、cm 等单位定义字体尺寸。
% 定义字体尺寸为父元素字体尺寸的某个百分比。
inherit fontSize 属性的值从父元素继承。

浏览器支持

Style fontSize 属性
Style fontSize 属性
Style fontSize 属性
Style fontSize 属性
Style fontSize 属性

所有主要浏览器都支持 fontSize 属性。

注意:

IE7 及更早的版本不支持 "inherit" 值。IE8 只有规定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。

实例

更改文本的字体尺寸:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>菜鸟教程(runoob.com)</title>

<script>

function displayResult(){

    document.getElementById("p1").style.fontSize="xx-large";

}

</script>

</head>

<body>

<p id="p1">这是一些文本。</p>

<br>

<button type="button" onclick="displayResult()">修改字体大小</button>

</body>

</html>

Style 对象