CARVIEW |
Select Language
HTTP/2 200
x-guploader-uploadid: AAwnv3Iwxu4TKMvWZdD9RXZqPpLzDZxunj876QZQcqQ93thx7GzbF2D4YoE7WR6IFebvUTN7
x-goog-generation: 1760058716142005
x-goog-metageneration: 1
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 286282
x-goog-meta-goog-reserved-file-mtime: 1760056735
x-goog-hash: crc32c=GYi3Pg==, md5=BJIoWLS7g9ANO49amFQyUw==
x-goog-storage-class: STANDARD
accept-ranges: none
expires: Fri, 10 Oct 2025 04:14:04 GMT
cache-control: public, max-age=3600
last-modified: Fri, 10 Oct 2025 01:11:56 GMT
etag: W/"04922858b4bb83d00d3b8f5a98543253"
content-type: text/html
age: 2106
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
alt-svc: clear
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
strict-transport-security: max-age=63072000
content-security-policy: default-src 'self'; script-src 'report-sample' 'self' 'wasm-unsafe-eval' https://www.google-analytics.com/analytics.js https://www.googletagmanager.com/gtag/js assets.codepen.io production-assets.codepen.io https://js.stripe.com 'sha256-XNBp89FG76amD8BqrJzyflxOF9PaWPqPqvJfKZPCv7M=' 'sha256-YCNoU9DNiinACbd8n6UPyB/8vj0kXvhkOni9/06SuYw=' 'sha256-PZjP7OR6mBEtnvXIZfCZ5PuOlxoDF1LDZL8aj8c42rw='; script-src-elem 'report-sample' 'self' 'wasm-unsafe-eval' https://www.google-analytics.com/analytics.js https://www.googletagmanager.com/gtag/js assets.codepen.io production-assets.codepen.io https://js.stripe.com 'sha256-XNBp89FG76amD8BqrJzyflxOF9PaWPqPqvJfKZPCv7M=' 'sha256-YCNoU9DNiinACbd8n6UPyB/8vj0kXvhkOni9/06SuYw=' 'sha256-PZjP7OR6mBEtnvXIZfCZ5PuOlxoDF1LDZL8aj8c42rw='; style-src 'report-sample' 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self'; connect-src 'self' developer.allizom.org bcd.developer.allizom.org bcd.developer.mozilla.org updates.developer.allizom.org updates.developer.mozilla.org https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com https://incoming.telemetry.mozilla.org https://observatory-api.mdn.allizom.net https://observatory-api.mdn.mozilla.net https://api.github.com/search/issues stats.g.doubleclick.net https://api.stripe.com; font-src 'self'; frame-src 'self' interactive-examples.mdn.mozilla.net interactive-examples.mdn.allizom.net mdn.github.io live-samples.mdn.mozilla.net live-samples.mdn.allizom.net *.mdnplay.dev *.mdnyalp.dev *.play.test.mdn.allizom.net https://v2.scrimba.com https://scrimba.com jsfiddle.net www.youtube-nocookie.com codepen.io survey.alchemer.com https://js.stripe.com; img-src 'self' data: *.githubusercontent.com *.googleusercontent.com *.gravatar.com mozillausercontent.com firefoxusercontent.com profile.stage.mozaws.net profile.accounts.firefox.com developer.mozilla.org mdn.dev interactive-examples.mdn.mozilla.net interactive-examples.mdn.allizom.net wikipedia.org upload.wikimedia.org https://mdn.github.io/shared-assets/ https://mdn.dev/ https://*.google-analytics.com https://*.googletagmanager.com www.gstatic.com; manifest-src 'self'; media-src 'self' archive.org videos.cdn.mozilla.net https://mdn.github.io/shared-assets/; child-src 'self'; worker-src 'self';
x-frame-options: DENY
origin-trial: AxVILwizhbMjxFeHOn1P3R8niO1RJY/smaK4B4d1rLzc1gTaxtXMSaTi+FoigYgCw40uFRDwFcEAeqDR+vVLOW4AAABfeyJvcmlnaW4iOiJodHRwczovL2RldmVsb3Blci5tb3ppbGxhLm9yZyIsImZlYXR1cmUiOiJQcml2YXRlQXR0cmlidXRpb25WMiIsImV4cGlyeSI6MTc0MjA3OTYwMH0=
x-cloud-trace-context: b94678596672109005ea283ce1a1afe7
date: Fri, 10 Oct 2025 03:49:10 GMT
server: Google Frontend
via: 1.1 google
vary: Accept-Encoding
content-encoding: gzip
x-cache: miss
top - CSS: カスケーディングスタイルシート | MDN
Toggle sidebar
>
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
top
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
* Some parts of this feature may have varying levels of support.
top
は CSS のプロパティで、位置指定要素の垂直位置の決定に関与します。位置指定されていない要素には効果はありません。
試してみましょう
top: 0;
top: 4em;
top: 10%;
top: 20px;
<section id="default-example">
<div class="example-container">
<div id="example-element">I am absolutely positioned.</div>
<p>
As much mud in the streets as if the waters had but newly retired from the
face of the earth, and it would not be wonderful to meet a Megalosaurus,
forty feet long or so, waddling like an elephantine lizard up Holborn
Hill.
</p>
</div>
</section>
.example-container {
border: 0.75em solid;
padding: 0.75em;
text-align: left;
position: relative;
width: 100%;
min-height: 200px;
}
#example-element {
background-color: #264653;
border: 4px solid #ffb500;
color: white;
position: absolute;
width: 140px;
height: 60px;
}
top
の効果は、要素がどの様に配置されているか(つまり、 position
プロパティの値)によって変わります。
position
がabsolute
またはfixed
に設定されている場合、top
プロパティは要素の上辺と包含ブロックの上辺との間の距離を指定します。position
がrelative
に設定されている場合、top
プロパティは要素の上辺が通常位置から下方へ移動する量を指定します。position
がsticky
に設定されている場合、top
プロパティは粘着制約矩形の計算に使用されます。position
がstatic
に設定されている場合、top
プロパティは効果がありません。
top
と bottom
の両方が指定されている場合は、 3 つの異なる場合があります。
position
がabsolute
またはfixed
に設定されており、height
が指定されていない(auto
または100%
である)場合、top
およびbottom
の両方が尊重されます。position
がrelative
に設定されているか、height
が指定されている場合、top
プロパティが優先され、bottom
プロパティは無視されます。position
がsticky
に設定されている場合、top
とbottom
の両方の値が考慮されます。つまり、粘着位置指定要素は、要素の位置ボックスがそのブロック内に収まっている限り、これら 2 つのプロパティの値に基づいて、そのブロック内で上下に移動できる可能性があります。
構文
css
/* <length> 値 */
top: 3px;
top: 2.4em;
/* 包含ブロックの高さに対する <percentage> */
top: 10%;
/* キーワード値 */
top: auto;
/* グローバル値 */
top: inherit;
top: initial;
top: revert;
top: revert-layer;
top: unset;
値
<length>
-
負、null、または正の
<length>
で、以下のものを表します。- 絶対位置指定要素の場合は、包含ブロックの上辺までの距離。
- 相対位置指定要素の場合は、通常の位置からの下方向への移動量。
<percentage>
-
包含ブロックの高さに対する
<percentage>
です。 auto
-
以下のように指定します。
inherit
-
値が親要素(包含ブロックとは限りません)の計算値と同じであることを示すキーワードです。そして、この計算値は
<length>
,<percentage>
, またはauto
キーワードと同様に扱われます。
公式定義
形式文法
top =
auto |
<length-percentage> |
<anchor()> |
<anchor-size()>
<length-percentage> =
<length> |
<percentage>
<anchor()> =
anchor( <anchor-name>? &&
<anchor-side> , <length-percentage>? )
<anchor-size()> =
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )
<anchor-name> =
<dashed-ident>
<anchor-side> =
inside |
outside |
top |
left |
right |
bottom |
start |
end |
self-start |
self-end |
<percentage> |
center
<anchor-size> =
width |
height |
block |
inline |
self-block |
self-inline
例
>位置指定要素を上から 10% に設定
css
body {
background: beige;
}
div {
position: absolute;
top: 10%;
right: 40%;
bottom: 20%;
left: 15%;
background: gold;
border: 1px solid blue;
}
html
<div>この内容の寸法は、辺の位置によって決まります。</div>
仕様書
Specification |
---|
CSS Positioned Layout Module Level 3> # insets> |
ブラウザーの互換性
Loading…
関連情報
inset
: 関連するすべてのプロパティであるtop
,bottom
,left
,right
の一括指定- 対応する論理的プロパティ:
inset-block-start
,inset-block-end
,inset-inline-start
,inset-inline-end
および一括指定のinset-block
とinset-inline
position