重なった背景レイヤーをcssで表現する
色違いだったり、画像のレイヤーが重なったデザインを擬似要素で表現する。
紙モノ的なデザイン。
見出し箇所などでよく見る気がする。
これでいうと、赤い背景レイヤーと緑枠のコンテンツ領域とが重なっているところ。
html
<div class="wrap"> <h1 class="ttl">タイトルとか</h1> <div class="content"> <div class="sec">内容とか</div> ...以下略 </div> </div>
css
.wrap{ /* 包含ボックス */ position: relative; z-index: 1; } .wrap::before{ /* 装飾部分 */ content: ""; display: block; position: absolute; top: 0; left: 0; z-index: 1; width: 100%; height: 100px; background-color: #fc402c; } .ttl{ position: relative; z-index: 3; /* 以下デザイン部分 */ padding: 20px 0; color: #fff; font-size: 1.5rem; font-weight: bold; text-align: center; } .sec{ position: relative; z-index: 3; /* 以下デザイン部分 */ width: 30%; height: 100px; padding: 10px; border: solid 2px #86c036; border-radius: 4px; background: #fff; color: #86c036; font-weight: bold; text-align: center; } .contente{ display: flex; justify-content: space-around; }
※コンテンツのz-index(ここでは適当に3)は、装飾パーツのz-indexより上ならばなんでも良い。
この場合h1のブロック要素を使ってコンテンツ領域全体をネガティブマージンで引き上げる、といった表現でもいいが、物理的にhtmlのタグを増やさない方が好みなのでよく使っている。
他にも表現があったら教えてください。