http://codepen.io/ColoO/pen/tfGap
javascrit を使用して、div タイプ 1 の z-index プロパティを変更します。div の絶対位置を設定する必要があります。
HTML
<div id="main">
<div id="type1">type1</div>
<div id="type2">type2</div>
</div>
<a href="#" onClick="type1()">appear type 1</a> |
<a href="#" onClick="type2()">appear type 2</a>
CSS
#main {
background:grey;
width:400px;
height:300px;
position:relative;
z-index:-12;
}
#type1{
position:absolute;
background: pink;
top:10px;
left:10px;
height:100px;
width:100px;
z-index:2;
}
#type2{
position:absolute;
background: red;
top:20px;
left:20px;
height:100px;
width:100px;
}
ジャバスクリプト
function type2() {
document.getElementById('type1').style.zIndex = -3;
}
function type1() {
document.getElementById('type1').style.zIndex = 2;
}
divを消したい場合は「style.zIndex = -3;」に変更 by "style.display = "none";" ジャバスクリプトで