h2見出しに CSS counter を使って行頭に連番を表示させてます。
連番は疑似要素の before に設定しています。
見出しが改行しない場合は想定通りのレイアウトになるのですが、見出しか長くて改行すると疑似要素の幅が
widthで指定しているにもかかわらず無視して縮んでしまいます。
なぜwidthが無視されるのでしょうか。また、また本体の長さにかからわず幅を固定する方法はないでしょうか。
html
1<div class="post"> 2 <h2>aaaaaaaa</h2> 3 <h2>ああああああああああああああああああああああああああああああああああああああああああああああ</h2> 4</div>
css
1.post h2{ 2 display: flex; 3 line-height: 4.2rem; 4 font-size: 1.8rem; 5 counter-increment: h2; 6} 7.post h2:before { 8 content: counter(h2); 9 background-color: #333; 10 color: #fff; 11 text-align: center; 12 width: 4.2rem; 13/* flex-basis: 4.2rem; */ 14 height: 4.2rem; 15 line-height: 4.2rem; 16 font-size: 1.8rem; 17 margin-right: 1.2rem; 18}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/10 11:56