私のサイトのコンポーネントをスタイリングするとき、span
の末尾に空白を追加すると、h2
の中の絶対位置が奇妙な方法で絶対位置に影響します。私は境界として使用するafter
要素です。境界線は、空白のないコンテンツの後ろに位置しますが、空白がある場合は内容の上に位置します。 You can see an example here。スパンの末尾の空白は、後の擬似要素の絶対配置に影響を与えます
これはなぜ異なってレンダリングされるのでしょうか?
HTML:
<h2>
<span>A test</span> <!-- the border appears 'after' the content -->
</h2>
<h2>
<span>A test </span> <!-- the border appears 'over' the content -->
</h2>
はCSS:
h2 {
position:relative;
height:1.625em/1;
}
h2 span {
font-size: 100%;
margin: 0;
padding: 0;
vertical-align: top;
display: inline-block;
1.625em/1 'MuseoSlab300','Times New Roman',serif;
}
span:after {
content: "";
border-bottom: 5px solid #7c61a0;
position: absolute;
bottom: 5px;
margin-left: 8px;
width: 100%;
}
'width:100% 'によって引き起こされた折り返しのようです。 –
注:どちらのケースもFirefoxで同じに見えますが、Chromeの違いがわかります。 – andi
問題を回避するためにこれを行う他の方法に興味がありますか?またはあなたはすでにそれを別に修正しましたが、遭遇したこの問題について興味がありますか? – andi