By MDN :
The first row has only a value in the container block, therefore the :: first-line pseudo-element affects only elements with the display value of the block, inline block, table or table. In all other cases :: the first row has no effect.
The following is an excerpt from the W3C Spec : ( Section 7.1.1 First Definition of Formatted String in CSS )
In CSS, the :: first-line pseudo-element can only have an effect when attached to a block-like container, such as a block block, inline block, table header, or table cell.
Since span elements are display: inline by default , the ::first-line selector does not affect it. If we change the display on span to inline-block or block , it will work.
p::first-line { color: #ff0000; font-variant: small-caps; } span::first-line { color: #ff0000; font-variant: small-caps; } span.block { display: block; } span.inline-block { display: inline-block; }
<h3>Default Span</h3> <span> This is to check span.This is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check span</span> <h3>Span with display as block</h3> <span class='block'> This is to check span.This is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check span</span> <h3>Span with display as inline-block</h3> <span class='inline-block'> This is to check span.This is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check spanThis is to check span</span> <p>This is to check p.This is to check p.This is to check p.This is to check p.This is to check p.This is to check p.This is to check p.This is to check p.This is to check p.This is to check p.This is to check p.This is to check p.This is to check p.</p>
Harry source share