z-index: ***;
ブラウザ |
|
---|---|
プロパティ |
z-index は、ボックスの重なりの順序を指定するプロパティです。
この指定は、positionプロパティで relative
、absolute
、fixed
を指定している場合に有効となります。
.example {
position: absolute;
top: 100px;
z-index: 2;
}
プロパティ名 | 値 | 説明 |
---|---|---|
z-index |
auto |
親要素と同じ階層にする (初期値) |
数値 | 値が大きいものほど前面(手前)に表示される (0 が基準) |
使用例
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>文書のタイトル</title>
<style type="text/css">
div {
width: 200px;
height: 100px;
position: absolute;
}
div.example1 {
z-index: 2;
background-color: #85b9e9;
top: 100px;
left: 0;
}
div.example2 {
z-index: 3;
background-color: #ffd78c;
top: 150px;
left: 100px;
}
div.example3 {
z-index: 1;
background-color: #bde9ba;
top: 50px;
left: 50px;
}
</style>
</head>
<body>
<div class="example1">ボックス1</div>
<div class="example2">ボックス2</div>
<div class="example3">ボックス3</div>
</body>
</html>
- 表示例