如何在“標(biāo)簽內(nèi)有效消除“標(biāo)簽間的間距?

如何在“標(biāo)簽內(nèi)有效消除“標(biāo)簽間的間距?

網(wǎng)頁布局中,精準(zhǔn)控制文本行高至關(guān)重要。line-height屬性通常能輕松解決此問題。然而,當(dāng)

標(biāo)簽嵌套在

標(biāo)簽內(nèi),并嘗試使用line-height: 0;消除段落間距時(shí),可能會(huì)出現(xiàn)意想不到的結(jié)果。 <p>問題:作者嘗試使用p { line-height: 0; }來消除</p><p>標(biāo)簽間的間距。在非</p><pre class="brush:php;toolbar:false">環(huán)境下,此方法有效。但當(dāng)代碼片段包含在<pre class="brush:php;toolbar:false">標(biāo)簽內(nèi)時(shí),p { line-height: 0; }失效,段落間距依然存在。即使添加pre { line-height: 0; }和pre p { line-height: 0; }也無法解決問題。 <p>解決方案:將line-height: 0;直接應(yīng)用于</p><pre class="brush:php;toolbar:false">元素本身。修改樣式為pre { line-height: 0; }即可。<pre class="brush:php;toolbar:false">標(biāo)簽會(huì)繼承并應(yīng)用其子元素的樣式,設(shè)置<pre class="brush:php;toolbar:false">標(biāo)簽行高為0,能有效影響其內(nèi)部所有元素(包括<p>標(biāo)簽)的行高,從而消除段落間距。</p>

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊15 分享