忍者ブログ
20 October

z-index :after :before で装飾したとき親要素を一番上にする

z-indexは positoin:static; 以外のpositioni指定をしていなければ効かない
親にはz-indexをつけない。つけたら一番上にならない


http://blog.56doc.net/Entry/415/
p{
  position:relative;
  top:30px;
  width:150px;
  height:150px;
  background-color:rgba(255,0,0,0.8);
}

p:before{
  content:"before擬似要素";
  position:absolute;
  top:-15px;
  left:15px;
  width:150px;
  height:150px;
  background-color:rgba(0,255,0,0.8);
  z-index:-1;
}

p:after{
  content:"after擬似要素";
  position:absolute;
  top:-30px;
  left:30px;
  width:150px;
  height:150px;
  background-color:rgba(0,0,255,0.8);
  z-index:-2;
}
PR