スタイルmaxWidthプロパティ
例
<div>要素の最大幅を設定します。
document.getElementById("myDiv").style.maxWidth = "100px";
定義と使用法
maxWidthプロパティは、要素の最大幅を設定または返します。
maxWidthプロパティは、ブロックレベルの要素、または絶対位置または固定位置の要素にのみ影響します。
注:要素の幅は、maxWidthプロパティで指定された値より大きくすることはできません。
ヒント:要素の最小幅を設定または返すには、minWidthプロパティを使用します。
ブラウザのサポート
Property | |||||
---|---|---|---|---|---|
maxWidth | Yes | Yes | Yes | Yes | Yes |
構文
maxWidthプロパティを返します。
object.style.maxWidth
maxWidthプロパティを設定します。
object.style.maxWidth = "none|length|%|initial|inherit"
プロパティ値
Value | Description |
---|---|
none | No limit on the width of the element. This is default |
length | Defines the maximum width in length units |
% | Defines the maximum width in % of the parent element |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
技術的な詳細
デフォルト値: | なし |
---|---|
戻り値: | 要素の最大幅を表す文字列 |
CSSバージョン | CSS2 |
その他の例
例
<div>要素の最大幅を返します。
alert(document.getElementById("myDiv").style.maxWidth);
関連ページ
CSSチュートリアル:CSSディメンション
CSSリファレンス:max-widthプロパティ
❮スタイルオブジェクト