CARVIEW |
Select Language
HTTP/2 200
content-type: text/html
x-guploader-uploadid: AAwnv3K01iXamJuscmeGHeELkBqLB6Xf81O4Yz8GrMAEUIAfc51WqCTi1XoeAdMd6tEwMURC
cache-control: public, max-age=3600
expires: Wed, 08 Oct 2025 08:19:45 GMT
last-modified: Wed, 08 Oct 2025 01:13:42 GMT
etag: W/"f8c16e290ae92ecc2ea3509f67e57e78"
x-goog-generation: 1759886022038606
x-goog-metageneration: 1
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 277971
x-goog-meta-goog-reserved-file-mtime: 1759883917
x-goog-hash: crc32c=YQ+cMQ==, md5=+MFuKQrpLswuo1CfZ+V+eA==
x-goog-storage-class: STANDARD
accept-ranges: none
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: 4eabef3174b1aed41ee1759481bd02da
date: Wed, 08 Oct 2025 07:19:45 GMT
server: Google Frontend
via: 1.1 google
vary: Accept-Encoding
content-encoding: gzip
x-cache: miss
z-index - CSS: カスケーディングスタイルシート | MDN
Toggle sidebar
>
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
z-index
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月.
z-index
は CSS のプロパティで、位置指定要素とその子孫要素、またはフレックスアイテムやグリッドアイテムの z 順を定義します。 z-index がより大きな要素はより小さな要素の上に重なります。
試してみましょう
z-index: auto;
z-index: 1;
z-index: 3;
z-index: 5;
z-index: 7;
<section class="default-example container" id="default-example">
<div id="example-element">Change my z-index</div>
<div class="block blue position1">z-index: 6</div>
<div class="block blue position2">z-index: 4</div>
<div class="block blue position3">z-index: 2</div>
<div class="block red position4">z-index: auto</div>
<div class="block red position5">z-index: auto</div>
<div class="block red position6">z-index: auto</div>
</section>
#example-element {
top: 15px;
left: 15px;
width: 180px;
height: 230px;
position: absolute;
/* center the text so it is visible even when z-index is set to auto */
line-height: 215px;
font-family: monospace;
background-color: #fcfbe5;
border: solid 5px #e3e0a1;
z-index: auto;
color: black;
}
.container {
display: inline-block;
width: 250px;
position: relative;
}
.block {
width: 150px;
height: 50px;
position: absolute;
font-family: monospace;
color: black;
}
.blue {
background-color: #e5e8fc;
border: solid 5px #112382;
/* move text to the bottom of the box */
line-height: 55px;
}
.red {
background-color: #fce5e7;
border: solid 5px #e3a1a7;
}
.position1 {
top: 0;
left: 0;
z-index: 6;
}
.position2 {
top: 30px;
left: 30px;
z-index: 4;
}
.position3 {
top: 60px;
left: 60px;
z-index: 2;
}
.position4 {
top: 150px;
left: 0;
z-index: auto;
}
.position5 {
top: 180px;
left: 30px;
z-index: auto;
}
.position6 {
top: 210px;
left: 60px;
z-index: auto;
}
位置指定されたボックス(つまり、position
が static
以外のもの)では、z-index
プロパティが以下のことを定義します。
- 現在の重ね合わせコンテキストにおけるボックスの重ね合わせレベル
- ボックスがローカルな重ね合わせコンテキストを作るかどうか
構文
css
/* キーワード値 */
z-index: auto;
/* <integer> 値 */
z-index: 0;
z-index: 3;
z-index: 289;
z-index: -1; /* 負の数はより低い優先度になる */
/* グローバル値 */
z-index: inherit;
z-index: initial;
z-index: revert;
z-index: revert-layer;
z-index: unset;
z-index
プロパティは、キーワード auto
または <integer>
のどちらかで指定します。
値
公式定義
初期値 | auto |
---|---|
適用対象 | 位置指定要素 |
継承 | なし |
計算値 | 指定通り |
アニメーションの種類 | integer |
重ね合わせコンテキストの生成 | あり |
形式定義
z-index =
auto |
<integer> |
inherit
例
>視覚的な階層を持つ要素
HTML
html
<div class="wrapper">
<div class="dashed-box">破線のボックス</div>
<div class="gold-box">金色のボックス</div>
<div class="green-box">緑色のボックス</div>
</div>
CSS
css
.wrapper {
position: relative;
}
.dashed-box {
position: relative;
z-index: 1;
border: dashed;
height: 8em;
margin-bottom: 1em;
margin-top: 2em;
}
.gold-box {
position: absolute;
z-index: 3; /* .gold-box を .green-box や .dashed-box の上に置く */
background: gold;
width: 80%;
left: 60px;
top: 3em;
}
.green-box {
position: absolute;
z-index: 2; /* .green-box を .dashed-box の上に置く */
background: lightgreen;
width: 20%;
left: 65%;
top: -25px;
height: 7em;
opacity: 0.9;
}
結果
仕様書
Specification |
---|
Cascading Style Sheets Level 2> # z-index> |
ブラウザーの互換性
Loading…
関連情報
- CSS
position
プロパティ - CSS の z-index を理解する