CSSのmargin-leftプロパティ
例
<p>要素の左マージンを30ピクセルに設定します。
p.ex1 {
margin-left: 30px;
}
以下の「自分で試してみてください」の例をもっと見てください。
定義と使用法
プロパティは、要素のmargin-left
左マージンを設定します。
注: 負の値を使用できます。
デフォルト値: | 0 |
---|---|
遺伝性の: | いいえ |
アニメート可能: | はい、個々のプロパティを参照してください。アニメート可能について読む |
バージョン: | CSS1 |
JavaScript構文: | オブジェクト.style.marginLeft = "100px" |
ブラウザのサポート
表の数字は、プロパティを完全にサポートする最初のブラウザバージョンを示しています。
Property | |||||
---|---|---|---|---|---|
margin-left | 1.0 | 6.0 | 1.0 | 1.0 | 3.5 |
CSS構文
margin-left: length|auto|initial|inherit;
プロパティ値
Value | Description | Play it |
---|---|---|
length | Specifies a fixed left margin in px, pt, cm, etc. Default value is 0px. Negative values are allowed. Read about length units | |
% | Specifies a left margin in percent of the width of the containing element | |
auto | The browser calculates a left margin | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
その他の例
例
<p>要素の左マージンをコンテナの幅の10%に設定します。
p.ex1 {
margin-left: 10%;
}
例
<p>要素の左マージンを2emに設定します。
p.ex1 {
margin-left: 2em;
}
関連ページ
CSSチュートリアル:CSSマージン
HTML DOMリファレンス:marginLeftプロパティ