天天看点

Style fontVariant 属性

Style 对象

定义和用法

fontVariant 属性设置或返回是否以小型大写字母显示字体。

这意味着所有的小写字母将被转换为大写,但相比其余文本,该字母将是较小的字体尺寸。

语法

设置 fontVariant 属性:

Object.style.fontVariant="normal|small-caps|inherit"

返回 fontVariant 属性:

Object.style.fontVariant

描述
normal 默认。字体是 normal(正常的)。
small-caps 字体显示为小型大写字母。
inherit fontVariant 属性的值从父元素继承。

浏览器支持

Style fontVariant 属性
Style fontVariant 属性
Style fontVariant 属性
Style fontVariant 属性
Style fontVariant 属性

所有主要浏览器都支持 fontVariant 属性。

注意:

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.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 对象