positionプロパティ
positionプロパティは、エレメントの位置を指定するプロパティです。親エレメントに対して絶対位置や相対位置、ウィンドウに対して絶対位置の設定やスクロールの操作時の位置を定義することができます。
もしもabsolute値を指定する場合は、親エレメントにposition:relative;またはfixed値を指定します。親エレメントがposition:static;ではwindowの表示部分の左端が基準になります。
position: relative; top: 50px; left: 100px;
関連プロパティ
配置位置を設定するには以下のプロパティを併用します。
配置の設定
以下のプロパティを使ってエレメントの表示位置を設定します。
関連プロパティ | 摘要 |
---|---|
top | 最上端が基準 |
bottom | 最下端が基準 |
left | 左端が基準 |
right | 右端が基準 |
前後位置の設定
z-indexプロパティで、エレメントの前後の表示順を設定します。
関連プロパティ | 摘要 |
---|---|
z-index | 前後の表示順 |
構文(Syntax)
CSS
position: static | absolute | fixed | relative | sticky | initial | inherit;
DOM(JavaScript)
String = object.style.position;
object.style.position="static | absolute | fixed | relative | sticky | initial | inherit";
値(Values)
Value | 摘要 |
---|---|
static | default値。エレメントに設定されている位置、位置を設定しても反映されない |
absolute | relative値またはfixed値が設定された親エレメントの左上端が初期位置、親エレメントに対して絶対配置 |
fixed | ウィンドウの表示部分の左上端が初期位置、ウィンドウに対して絶対配置 |
relative | 親エレメントの左上端が初期位置、親エレメントに対して相対配置 |
sticky | ウィンドウのスクロール操作時のエレメントの位置を定義。sectionエレメント、topプロパティ、z-indexプロパティを合わせて使う |
initial | 初期値に戻す |
inherit | 親エレメントの値を継承 |
備考(Remarks)
初期値(Default value) | static |
継承(Inherited) | No |
CSS Animation | No |
Example
positionの例です。親エレメントに対して相対配置に配置します。
関連(Related)
HTML、CSS、DOMのHTMLエレメント、Windowに関する用途一覧です。
HTML
CSS
- サイズ
-
- height、 width、 max-height、 max-width、 min-height、 min-width、 resize
- スクロール追加
- overflow、 overflow-x、 overflow-y
- マージン、パディング、ボーダー
-
- 共通
- box-sizing、 display
- マージン
- margin、 margin-bottom、 margin-left、 margin-right、 margin-top
- パディング
- padding、 padding-bottom、 padding-left、 padding-right、 padding-top
- ボーダー、罫線
-
- 全体
- border、 border-collapse、 border-color、 border-spacing、 border-style、 border-width
- 上辺
- border-top、 border-top-color、 border-top-left-radius、 border-top-right-radius、 border-top-style、 border-top-width
- 下辺
- border-bottom、 border-bottom-color、 border-bottom-left-radius、 border-bottom-right-radius、 border-bottom-style、 border-bottom-width
- 左辺
- border-left、 border-left-color、 border-left-style、 border-left-width
- 右辺
- border-right、 border-right-color、 border-right-style、 border-right-width
- 角を丸に
- border-radius
- 画像を線に
- border-image、 border-image-outset、 border-image-repeat、 border-image-slice、 border-image-source、 border-image-width
- アウトライン
- outline、 outline-color、 outline-offset、 outline-style、 outline-width
- 配置
-
- 位置調整
- bottom、 left、 right、 top、 position、 z-index
- 横並び(フレックス)
- display:flex;、 align-content、 align-items、 align-self、 justify-content、 flex-wrap、 flex-basis、 flex-direction、 flex-flow
- 配列(グリッド)
- display:grid;、 grid-area、 grid-auto-columns、 grid-auto-flow、 grid-auto-rows、 grid-column、 grid-column-end、 grid-column-gap、 grid-column-start、 grid-gap、 grid-row、 grid-row-end、 grid-row-gap、 grid-row-start、 grid-template、 grid-template-areas、 grid-template-columns、 grid-template-rows、
- フレックス、グリッドの共通 横並び順
- order
- 背景
- background、 background-attachment、 background-blend-mode、 background-clip、 background-color、 background-image、 background-origin、 background-position、 background-repeat、 background-size、 linear-gradient、 radial-gradient
- フィルタ、加工
-
- filter、 transform、 transform-origin
- ブレンド
- isolation、 linear-gradient()、 mix-blend-mode、 radial-gradient()
- 影
- box-shadow
- 透過
- opacity
- 回転
- backface-visibility、
- 立体
- perspective、 perspective-origin
- 切り取り
- clip-path
- カラム
- column-fill、 column-gap、 column-rule、 column-rule-color、 column-rule-style、 column-rule-width、 column-span、 column-width、 columns
- ページ内移動
- scroll-behavior
- 表示、非表示
- visibility
DOM
HTMLエレメント
- インターフェース、クラス
- Document、 Element、 FocusEvent、 Attr
- イベント
- blur、 focus、 focusin、 focusout、 load、 resize、 scroll、 toggle
- プロパティ
- メソッド
Window
- インターフェース
- HashChangeEvent、 PageTransitionEvent、 Window
- イベント
- beforeunload、 hashchange、 load、 pagehide、 pageshow、 unload
- プロパティ
- newURL、 oldURL、 persisted
- メソッド
- clearTimeout()、 setTimeout()