What's the difference between p ::first-letter
and p::first-letter
?
p::first-letter
can successfully select the first letter inside a paragraph, but p ::first-letter
cannot.
Definition and UsageThe ::before selector inserts something before the content of each selected element(s). Use the content property to specify the content to insert. Use the ::after selector to insert something after the content.
::first-letter (:first-letter) The ::first-letter CSS pseudo-element applies styles to the first letter of the first line of a block-level element, but only when not preceded by other content (such as images or inline tables).
I would recommend that you use the following code in CSS: text-transform:uppercase; Make sure you put it in your class.
An initial letter is the first character of a sentence that is enlarged, positioned, and styled in a decorative or graphic way. It is commonly used to draw attention to a paragraph, chapter or section, article, ad copy – any important text in print and the web, as well as other digital media.
The selector p::first-letter
selects the first letter inside the p
whereas the p ::first-letter
selects the first letter within the child elements of the p
.
p ::first-letter
is equivalent to p *::first-letter
. The below is what the specs say:
If a universal selector represented by * (i.e. without a namespace prefix) is not the only component of a sequence of simple selectors selectors or is immediately followed by a pseudo-element, then the * may be omitted and the universal selector's presence implied.
Note: Even though the selector (p ::first-letter
) itself points to the first letter inside all child elements, the ::first-letter
selector works only on block or inline-block elements and hence wouldn't work on a span
unless its display
is modified.
p ::first-letter {
color: red;
}
p::first-letter {
color: blue;
}
span{
display: inline-block;
}
<p>Some text <span>inside a span</span> and <span>inside this span too</span>
</p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With