z-indexは要素のボックスの重なり順を指定します。
「position: static」を指定した場合はz-indexは有効となりません。
| CSS Ver. | 適用要素 | 継承 |
|---|---|---|
| 2.1 | 全要素 | しない |
| 構文 | |
|---|---|
|
z-index : 値 | auto ; |
|
| プロパティ/設定値 | 意味 |
|
z-index: 0; z-index: 1; z-index: -1; |
優先度を数値で指定 大きい値ほど最前面に表示される |
| z-index: auto; | ブラウザに委ねる 「z-index:0」とは意味が異なる |
| デフォルト:「タグ毎のスタイル初期値」を参照 | |
<style type="text/css">
.c_yellow{
z-index : 0;
position : relative;
width : 300px;
height : 200px;
border : 10px solid yellow;
background : rgba(255, 255, 0, 0.7);
}
.c_blue{
z-index : 1;
position : absolute;
top : 40px;
left : 20px;
width : 150px;
height : 100px;
border : 10px solid blue;
background : rgba(0, 0, 255, 0.7);
}
.c_green{
z-index : 3;
position : absolute;
top : 70px;
left : 75px;
width : 150px;
height : 100px;
border : 10px solid green;
background : rgba(0, 128, 0, 0.7);
}
.c_red{
z-index : 2;
position : absolute;
top : 10px;
left : 110px;
width : 150px;
height : 100px;
border : 10px solid red;
background : rgba(255, 0, 0, 0.7);
}
<!-- html -->
<div class="c_yellow">
<div class="c_blue"></div>
<div class="c_green"></div>
<div class="c_red"></div>
</div>
z-indexを変えると・・・
| ボックス色 | z-index値 |
|---|---|
| 黄色 | |
| 青色 | |
| 緑色 | |
| 赤色 |
| 関連するCSS(STYLE) | |
|---|---|
| bottom | 基点の下辺からの距離 |
| caption-side | テーブルのキャプションの表示位置 |
| clear | 回り込みの解除 |
| display | ボックスの種類 |
| float | 配置と回り込み |
| overflow | オーバーフローしたコンテンツの表示 |
| overflow-x | 横方向にオーバーしたコンテンツの表示 |
| overflow-y | 縦方向にオーバーしたコンテンツの表示 |
| position | 配置方法 |
| vertical-align | 縦(垂直)方向の文字位置 |
| left | 基点の左辺からの距離 |
| right | 基点の右辺からの距離 |
| top | 基点の上辺からの距離 |