【CSS】見出しデザインをまとめてみる(左右に線を引くとか)
- 更新
- デザインのメモ



左右に線を引く
よく見かけますね。
線を引いて、背景白のテキストを乗せるって感じですね。
コードを見る(HTML・CSS)
HTML
<h1 class="line01"><span>【CSS】見出しデザイン(左右に線を引く)</span></h1>
CSS
/* ---------- 01 背景で線を切る ---------- */
.line01 {
position: relative;
color: #2b2a27;
font-size: 22px;
font-weight: bold;
text-align: center;
}
.line01::before {
content: '';
position: absolute;
top: 48%;
left: 0;
right: 0;
border-top: 1px solid #2b2a27;
}
.line01 > span {
position: relative;
display: inline-block;
padding: 0 8px;
background-color: #fff;
}
左右に線を引く(flexboxを使ってみる)
コードを見る(HTML・CSS)
HTML
<h1 class="line02">【CSS】flexboxを使った見出しデザイン(左右に線を引く)</h1>
CSS
/* ---------- 02 flexbox を使う ---------- */
.line02 {
display: flex;
justify-content: center;
align-items: center;
color: #2b2a27;
font-size: 22px;
font-weight: bold;
}
.line02::before, .line02::after {
content: '';
width: 60px;
height: 1px;
background-color: #2b2a27;
}
.line02::before {
margin-right: 30px;
}
.line02::after {
margin-left: 30px;
}
さいごに





