Style fontSize 屬性

Style 對象參考手冊 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 屬性的值從父元素繼承。


流覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要流覽器都支持 fontSize 屬性。

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


實例

實例

更改文本的字體尺寸:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.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 對象參考手冊 Style 對象