HTML DOM Style fontSize 屬性

2018-08-04 20:41 更新

Style fontSize 屬性

Style 對象參考手冊 Style 對象

定義和用法

fontSize 屬性設(shè)置或返回文本的字體尺寸。

語法

設(shè)置 fontSize 屬性:

Object.style.fontSize="value|inherit"

返回 fontSize 屬性:

Object.style.fontSize

描述
xx-small
x-small
small
medium
large
x-large
xx-large
把字體的尺寸設(shè)置為不同的固定尺寸,從 xx-small 到 xx-large。
smaller 把字體尺寸減小一個相對單位。
larger 把字體尺寸增大一個相對單位。
length 使用 px、cm 等單位定義字體尺寸。
% 定義字體尺寸為父元素字體尺寸的某個百分比。
inherit fontSize 屬性的值從父元素繼承。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

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


實例

實例

更改文本的字體尺寸:

<html>
<head>
<script>
function displayResult()
{
document.getElementById("p1").style.fontSize="xx-large";
}
</script>
</head>
<body>

<p id="p1">This is some text.</p>
<br>

<button type="button" onclick="displayResult()">Change font size</button>

</body>
</html>

嘗試一下 ?


Style 對象參考手冊 Style 對象
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號