擬似要素を利用して上下に二重のラインを引いた見出しにキャッチコピーなどを入れるサブテキストエリアを追加したものです。
<h1 class="cp_h1title"><span title="サブテキスト">見出しテキスト</span></h1>
.cp_h1title {
position: relative;
display: flex;
justify-content: center;/*左右中央配置*/
padding: 10px;
}
.cp_h1title::before,
.cp_h1title::after {
position: absolute;
left: 0;
content: '';
width: 100%;
height: 6px;/*ボーダー全体の高さ*/
border-color: #333;
border-style: solid;
}
.cp_h1title::before {/*上ボーダー*/
top: 0;
border-width:2px 0 1px 0;
}
.cp_h1title::after {/*下ボーダー*/
bottom: 0;
border-width:1px 0 2px 0;
}
.cp_h1title span {
position: relative;
display: flex;
justify-content: center;/*左右中央配置*/
}
.cp_h1title span::before {/*サブテキスト*/
position: absolute;
content: attr(title);
top: -1em;
background: #ffffff;
font-size: 50%;
white-space: nowrap;
padding: 0 10px;
}
CSS3などで新たに追加された要素・装飾方法など、日々コードを書いていないと忘れてしまったり、ささっとプロトタイプを作る時などちょっとしたことに時間をかけている暇はない。そんな時に「あ〜、あれストックしときゃよかったなぁ」って困った自分用のストックブログです。カスタマイズなどがしやすいよう、昨今のweb制作に取り入れられる一般的なコードを中心に掲載しています。
@CopypetJp More Info