-3

 <div class="ex1">
      <div>
        <p></p>
        <p>Exmaple 1</p>
        <p>Exmaple 2</p>
      </div>
    </div>

i can't select first character in "Exmaple 1" with css and i finding solution

Thanks for support

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
  • 1
    What do you mean by first character? The letter **"E"** ? – Carl Binalla Oct 25 '17 at 09:05
  • After reading your question , the answer, your comments to the answer. I suggest you start off by researching a little bit about CSS selectors. You said : ' i can't find a solution ' ( something like that ) . You can find a solution just by searching : ' style first letter css ' and then ' select second element css ' etc. Invest more in your own development, ask here only after you have tried ( really tried ) to find a solution by yourself – Mihai T Oct 25 '17 at 11:50

1 Answers1

4

If you are talking about styling the first letter, then use :first-letter pseudo-element

.ex1 p:first-letter{
  color:red;
  font-size:2em;
}
<div class="ex1">
  <div>
    <p>Example 1</p>
    <p>Example 2</p>
  </div>
</div>

If you want to only apply it in the first p then also use :first-of-type

.ex1 p:first-of-type:first-letter{
  color:red;
  font-size:2em;
}
<div class="ex1">
  <div>
    <p>Example 1</p>
    <p>Example 2</p>
  </div>
</div>

Finally, if you just want to target the second element then use :nth-child(2) or the second p then :nth-of-type(2)

.ex1 p:nth-child(2):first-letter{
  color:red;
}
.ex1 p:nth-of-type(2):first-letter{
    font-size:2em;
}
<div class="ex1">
  <div>
    <p></p>
    <p>Example 1</p>
    <p>Example 2</p>
  </div>
</div>
Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317