スタイル左プロパティ
例
<button>要素の左位置を設定します。
document.getElementById("myBtn").style.left = "100px";
定義と使用法
leftプロパティは、配置された要素の左位置を設定または返します。
このプロパティは、パディング、スクロールバー、境界線、マージンなど、要素の左側の位置を指定します。
ヒント: positioned要素は、positionプロパティがrelative、absolute、またはfixedに設定されている要素です。
ヒント:配置された要素の正しい位置を設定または戻すには、rightプロパティを使用します。
ブラウザのサポート
Property | |||||
---|---|---|---|---|---|
left | Yes | Yes | Yes | Yes | Yes |
構文
左側のプロパティを返します。
object.style.left
左側のプロパティを設定します。
object.style.left = "auto|length|%|initial|inherit"
プロパティ値
Value | Description |
---|---|
auto | Lets the browser set the left position. This is default |
length | Defines the left position in length units. Negative values are allowed |
% | Sets the left position in % of the width 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>要素の左側の位置を設定します。
document.getElementById("myDIV").style.left = "100px";
例
負の値の使用-<div>要素の左側の位置を設定します。
document.getElementById("myDIV").style.left = "-100px";
例
<div>要素の左側の位置を返します。
alert(document.getElementById("myDiv").style.left);
関連ページ
CSSチュートリアル:CSSポジショニング
CSSリファレンス:leftプロパティ
❮スタイルオブジェクト