重なりの順序を指定する

[新着] Webテンプレートを仮オープンしました


z-index: ***;

ブラウザ
Internet Explorer Netscape Firefox Opera
参考
書式基本 要素名 クラス ID

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

この順序の指定は、position プロパティで relativeabsolutefixed を指定している場合に有効です。


#example {
position: absolute;
top: 10px;
left: 30%;

z-index: 0;
}


z-index 順序を数値で指定します(0 に近いほど背面になります)

※デフォルトは auto(自動)です。(例:z-index: auto


使用例

<html>
<head>
<title>TAG index Webサイト</title>

<style type="text/css">
<!--

div {
width: 200px;
height: 100px;
position: absolute;

}

#example1 {
z-index: 1;
background-color: #85b9e9;
top: 100px;
left: 50px;

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

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

}


-->
</style>

</head>
<body>

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

</body>
</html>

これをブラウザで見ると次のように表示されます



[特集] レンタルサーバー比較 & サーバー選びのチェックポイント

サイト内検索について - ベーシック版