天天看點

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 對象