Style colorプロパティ

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

定義と使い方

color プロパティは、テキストの色を設定または返します。

構文

color プロパティの設定:

Object.style.color="color|inherit"

color プロパティの取得:

Object.style.color

值 説明
color テキストの色を指定します。CSS 色値の中で、可能な色値の完全なリストを参照してください。
inherit color プロパティの値は親要素から継承されます。


ブラウザ対応

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

注意: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.color="#ff0000";
    document.getElementById("p2").style.color="magenta";
}
</script>
</head>
<body>

<p id="p1">これはサンプル段落です。</p>
<p id="p2">これもサンプル段落です。</p>
<br>
<input type="button" onclick="displayResult()" value="テキストの色を変更">

</body>
</html>

試してみる »


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