HTML DOM Style fontVariant 屬性
定義和用法
fontVariant 屬性設置或返回是否以小型大寫字母顯示字體。
這意味著所有的小寫字母將被轉換為大寫,但相比其余文本,該字母將是較小的字體尺寸。
語法
設置fontVariant 屬性:
Object.style.fontVariant="normal|small-caps|inherit"
返回fontVariant 屬性:
Object.style.fontVariant
值 | 描述 |
---|---|
normal | 默认。字体是 normal(正常的)。 |
small-caps | 字体显示为小型大写字母。 |
inherit | fontVariant 属性的值从父元素继承。 |
瀏覽器支持
所有主要瀏覽器都支持fontVariant 屬性。
注意: IE7及更早的版本不支持"inherit"值。IE8 只有規定了!DOCTYPE 才支持"inherit"。 IE9 支持"inherit"。
實例
實例
更改字體為小型大寫字母:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontVariant="small-caps";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<p>THIS IS SOME TEXT.</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.fontVariant="small-caps";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<p>THIS IS SOME TEXT.</p>
<br>
<button type="button" onclick="displayResult()">修改字體</button>
</body>
</html>
嘗試一下»
Style對象