スタイルカラープロパティ
例
さまざまな要素のテキストの色を設定します。
document.getElementById("myH2").style.color = "#ff0000";
document.getElementById("myP").style.color = "magenta";
document.getElementById("myP2").style.color = "blue";
document.getElementById("myDiv").style.color = "lightblue";
定義と使用法
colorプロパティは、テキストの色を設定または返します。
ブラウザのサポート
Property | |||||
---|---|---|---|---|---|
color | Yes | Yes | Yes | Yes | Yes |
構文
colorプロパティを返します。
object.style.color
colorプロパティを設定します。
object.style.color = "color|initial|inherit"
プロパティ値
Value | Description |
---|---|
color | Specifies the color of the text. Look at CSS Color Values for a complete list of possible color values |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
技術的な詳細
デフォルト値: | 指定されていない |
---|---|
戻り値: | 要素のテキストの色を表す文字列 |
CSSバージョン | CSS1 |
その他の例
例
<p>要素のテキストの色を返します。
alert(document.getElementById("myP").style.color);
関連ページ
CSSチュートリアル:CSSテキスト
CSSリファレンス:カラープロパティ
❮スタイルオブジェクト