1. Home
  2. スタイルシート CSS
  3. ボックス
  4. 重なりの順序を指定する

重なりの順序を指定する


z-index: ***;

ブラウザ
IE
Fx
Sf
Cr
O
特性
z-index

z-index は、ボックスの重なりの順序を指定するプロパティです。

この指定は、positionプロパティrelativeabsolutefixed を指定している場合に有効となります。



.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: 50px;
}

div.example2 {
z-index: 3;
background-color: #ffd78c;
top: 150px;
left: 200px;
}

div.example3 {
z-index: 1;
background-color: #bde9ba;
top: 50px;
left: 150px;
}

</style>

</head>
<body>

<div class="example1">ボックス1</div>
<div class="example2">ボックス2</div>
<div class="example3">ボックス3</div>

</body>
</html>

表示例


ボックス

ページの先頭へ


inserted by FC2 system