Style fontWeightプロパティ

Style 对象参考手册Style オブジェクト

定義と使い方

fontWeight プロパティは、フォントの太さを設定または返します。

構文

fontWeight プロパティを設定する:

Object.style.fontWeight="value"

fontWeight プロパティを返す:

Object.style.fontWeight

值 説明
normal デフォルト。フォントは normal(標準)です。
lighter より細いフォントを定義します。
bold 太字を定義します。
bolder より太いフォントを定義します。
100
200
300
400
500
600
700
800
900
細から太までの文字を定義します。400 は normal に相当し、700 は bold に相当します。
inherit fontWeight プロパティの値は親要素から継承されます。


ブラウザサポート

Internet ExplorerFirefoxOperaGoogle ChromeSafari

すべての主要ブラウザが fontWeight プロパティをサポートしています。

注意:IE7 以前のバージョンは "inherit" 値をサポートしていません。IE8 は !DOCTYPE が指定されている場合のみ "inherit" をサポートします。IE9 は "inherit" をサポートします。


例

例

フォントの太さを変更する:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.com)</title>
<script>
function displayResult(){
    document.getElementById("p1").style.fontWeight="900";
}
</script>
</head>
<body>

<p id="p1">これはテキストです。</p>
<br>
<button type="button" onclick="displayResult()">フォントの太さを変更</button>

</body>
</html>

試してみる »


Style 对象参考手册Style オブジェクト その他の拡張