2017-01-11 8 views
0

https://codepen.io/bazzle/pen/jyWdjMCSS第一の型、親のではなく、さらに子孫が

私が最初にpではなく、BLOCKQUOTE内にネストされたp、またはその他の要素を選択します。言い換えれば

<div class="article__body"> 
    <p> 
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
</p> 
<blockquote> 
    <p> 
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
    </p> 
</blockquote> 
<p> 
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
</p> 
</div> 

S 'のp孫のではなく、' すべての子pのうちp最初のCSS(以下)

.article__body{ 
     p:first-of-type{ 
      background-color:green; 
     } 
} 
+3

を試してみてください。あなたは真剣に質問する前に検索を検討する必要があります。 – Harry

+0

@ハリーはい、正確に。 –

+0

'.article__body> p:first-child {}'? – Banzay

答えて

0

たぶん、あなたはこの試してみてください:

.article_body p:nth-of-type(1){ 
    background-color:green; 
} 

または単にクラスを作成してくださいHTLM:<p class="yourclass"></p>

CSS:.yourclass{background-color:green;}

0

私は `>`コンビネータを使っ

.article__body p:nth-of-type(1){ 
      background-color:green; 
     }