HTML DOM Style fontSizeAdjust 屬性
定義和用法
fontSizeAdjust 屬性設置或返回文本的字體aspect 值。
所有字體都有aspect值 ,即小寫字母"x"和大寫字母"X"之間的尺寸差異。
當第一選擇字體不可用時,fontSizeAdjust 屬性讓您更好地控製字體尺寸。 當某種字體不可用時,瀏覽器使用指定的第二種字體。 這可能會導致字體尺寸的改變。 為了防止這種情況,請使用該屬性。
當瀏覽器知道第一選擇字體的aspect 值時,瀏覽器可以計算出使用第二選擇字體顯示文本時要使用的字體尺寸。
語法
設置fontSizeAdjust 屬性:
Object.style.fontSizeAdjust="none|value|inherit"
返回fontSizeAdjust 屬性:
Object.style.fontSizeAdjust
值 | 描述 |
---|---|
none | 默认。不要保留第一选择字体的 x-height。 |
value | 保留第一选择字体的 x-height,并计算字体的 aspect 值比率。 使用的公式:首选字体的字体尺寸 * (第一选择字体的 aspect 值 / 可用字体的 aspect 值) = 可用字体的字体尺寸 实例:如果 14px 的 Verdana(aspect 值是 0.58)不可用,但是某个可用的字体(Times New Roman)的 aspect 值是 0.46,那么替代字体的尺寸将是 14*(0.58/0.46) = 17.65px。 |
inherit | fontSizeAdjust 属性的值从父元素继承。 |
瀏覽器支持
只有Firefox 支持fontSizeAdjust 屬性。
實例
實例
調整字體尺寸:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontSizeAdjust="0.58";
}
</script>
</head>
<body>
<p id="p1">這是一些文本</p>
<br>
<button type="button" onclick="displayResult()">調整字體大小</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontSizeAdjust="0.58";
}
</script>
</head>
<body>
<p id="p1">這是一些文本</p>
<br>
<button type="button" onclick="displayResult()">調整字體大小</button>
</body>
</html>
嘗試一下»
Style對象