--- title: top slug: Web/CSS/top tags: - CSS - CSS Positioning - CSS Property - Reference - 'recipe:css-property' translation_of: Web/CSS/top ---
top は CSS のプロパティで、位置指定要素の垂直位置の決定に関与します。位置指定されていない要素には効果はありません。
このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 https://github.com/mdn/interactive-examples をクローンしてプルリクエストを送信してください。
top の効果は、要素がどの様に配置されているか (つまり、 {{cssxref("position")}} プロパティの値) によって変わります。
position が absolute または fixed に設定されている場合、 top プロパティは要素の上辺と包含ブロックの上辺との間の距離を指定します。position が relative に設定されている場合、 top プロパティは要素の上辺が通常位置から下方へ移動する量を指定します。position が sticky に設定されている場合、 top プロパティは粘着制約矩形の計算に使用されます。position が static に設定されている場合、 top プロパティは効果がありません。top と {{cssxref("bottom")}} の両方が指定されており、 position が absolute または fixed に設定されており、かつ {{cssxref("height")}} が未指定 (auto または 100% のどちらか) の場合は、 top と bottom の距離が尊重されます。それ以外の場合、 {{cssxref("height")}} が何らかの形で制約されていた場合、または position が relative に設定されていた場合は、 top プロパティが優先されて bottom プロパティは無視されます。
/* <length> 値 */ top: 3px; top: 2.4em; /* 包含ブロックの高さに対する <percentage> */ top: 10%; /* キーワード値 */ top: auto; /* グローバル値 */ top: inherit; top: initial; top: unset;
autoheight: auto は内容物の高さに基づいて決まります。また、 bottom も auto であった場合は、要素は垂直方向には静的要素が配置される場合と同様に配置されます。bottom も auto であった場合は、垂直方向には移動しません。inheritauto キーワードと同様に扱われます。{{CSSInfo}}
body {
background: beige;
}
div {
position: absolute;
top: 10%;
right: 40%;
bottom: 20%;
left: 15%;
background: gold;
border: 1px solid blue;
}
<div>この内容の寸法は、辺の位置によって決まります。</div>
{{EmbedLiveSample('Examples','100%','200')}}
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName('CSS3 Positioning', '#propdef-top', 'top')}} | {{Spec2('CSS3 Positioning')}} | sticky の位置の動作を追加 |
| {{SpecName('CSS2.1', 'visuren.html#propdef-top', 'top')}} | {{Spec2('CSS2.1')}} | 初回定義 |
{{Compat("css.properties.top")}}