對于具有用戶生成內容的網站,我想添加首字下沉,但前提是該p元素是article(例如)的第一個子元素。
我嘗試了first-childwith 的各種組合,:is但無法使其正常作業。
例如使用此標記:
<article>
<h2>Heading</h2>
<p>Text..</p>
</article>
我不希望出現首字下沉,因為標題已經有了。
但是有了這個:
<article>
<p>Text.. (this should start with drop cap)</p>
<p>Text..</p>
</article>
我想要第一個字母的首字母下沉。
這只能通過 CSS 來實作嗎?
還有一種情況,第一個p包含只是img由于 Markdown 決議器,但我想我對此無能為力。
uj5u.com熱心網友回復:
使用article p:first-child:first-letter目標的每一篇文章的第一對孩子的第一個字母。
article p:first-child:first-letter {
font-size: 20px;
}
<article>
<p>Text.. (article without heading and dropcap)</p>
<p>Text..</p>
</article>
<hr/>
<article>
<h1>Article with heading and without dropcap</h1>
<p>Text..</p>
<p>Text..</p>
</article>
請參閱https://developer.mozilla.org/en-US/docs/Web/CSS/:first-child和https://developer.mozilla.org/en-US/docs/Web/CSS/::first-信如何這兩個偽類的作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/326576.html
標籤:css
上一篇:根據條件添加或洗掉類
下一篇:為什么我的文字不換行并被切斷?
