Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between p ::first-letter and p::first-letter? [duplicate]

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.

like image 550
Yishu Fang Avatar asked Mar 03 '16 15:03

Yishu Fang


People also ask

What is :: before and :: after?

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.

Can I use :: first letter?

::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).

How do you capitalize the first letter of the first word in CSS?

I would recommend that you use the following code in CSS: text-transform:uppercase; Make sure you put it in your class.

How do you use initial letter?

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.


1 Answers

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>
like image 176
Harry Avatar answered Oct 21 '22 10:10

Harry