スタイルフォントプロパティ
例
要素のフォントを設定します。
document.getElementById("demo").style.font = "italic bold 20px arial,serif";
定義と使用法
fontプロパティは、最大6つの個別のフォントプロパティを省略形で設定または返します。
このプロパティを使用すると、以下を(この順序で)設定/返すことができます。
- フォントスタイル
- フォントバリアント
- フォントの太さ
- フォントサイズ
- 行の高さ
- フォントファミリー
font-sizeとfont-familyが必要です。他の値の1つが欠落している場合は、デフォルト値が挿入されます(存在する場合)。
上記のプロパティは、個別のスタイルプロパティで設定することもできます。制御性を向上させるために、上級者以外の作成者には、個別のプロパティを使用することを強くお勧めします。
ブラウザのサポート
Property | |||||
---|---|---|---|---|---|
font | Yes | Yes | Yes | Yes | Yes |
構文
フォントプロパティを返します。
object.style.font
フォントプロパティを設定します。
object.style.font = "font-style font-variant font-weight font-size/line-height|caption|icon|menu|
message-box|small-caption|status-bar|initial|inherit;"
プロパティ値
Value | Description |
---|---|
style | Sets the font-style |
variant | Sets the text in a small-caps font |
weight | Sets the boldness of the font |
size | Sets the size of the font |
lineHeight | Sets the distance between lines |
family | Sets the font face |
caption | The font used for captioned controls (like buttons, drop-downs, etc.) |
icon | The font used to label icons |
menu | The font used in menus |
message-box | The font used in dialog boxes |
small-caption | The font used in small controls |
status-bar | The font used in window status bars |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
技術的な詳細
デフォルト値: | 指定されていない |
---|---|
戻り値: | 要素のさまざまなフォントプロパティを表す文字列 |
CSSバージョン | CSS1 |
その他の例
例
要素のフォントを返します。
alert(document.getElementById("demo").style.font);
関連ページ
CSSチュートリアル:CSSフォント
CSSリファレンス:フォントプロパティ
❮スタイルオブジェクト