The
::first-letter CSS pseudo-element selects the first letter of the first line of a block, if it is not preceded by any other content (such as images or inline tables) on its line.
The first letter of an element is not necessarily trivial to identify:
- Punctuation, that is any characters defined in Unicode in the open (Ps), close (Pe), initial quote(Pi), final quote (Pf) and other punctuation (Po) classes, preceding or immediately following the first letter is also matched by this pseudo-element.
- Similarly some languages have digraphs that are always capitalized together, like the
IJin Dutch. In these rare cases, both letters of the digraph should be matched by the::first-letterpseudo-element. (This is poorly supported by browsers, check the browser compatibility table). - Finally, a combination of the
::beforepseudo-element and thecontentproperty may inject some text at the beginning of the element. In that case,::first-letterwill match the first letter of this generated content.
A first line has meaning only in a block-container box, therefore the
::first-letter pseudo-element has an effect only on elements with a display value of block, inline-block, table-cell, list-itemor table-caption. In all other cases, ::first-letter has no effect.
Only a small subset of all CSS properties can be used inside a declaration block of a CSS ruleset containing a selector using the
::first-letter pseudo-element:- All font properties :
font,font-style,font-feature-settings,font-kerning,font-language-override,font-stretch,font-synthesis,font-variant,font-variant-alternates,font-variant-caps,font-variant-east-asian,font-variant-ligatures,font-variant-numeric,font-variant-position,font-weight,font-size,font-size-adjust,line-heightandfont-family. - All background properties :
background,background-color,background-image,background-clip,background-origin,background-position,background-repeat,background-size,background-attachment, andbackground-blend-mode. - All margin properties:
margin,margin-top,margin-right,margin-bottom,margin-left. - All padding properties:
padding,padding-top,padding-right,padding-bottom,padding-left. - All border properties: the shorthands
border,border-style,border-color,border-width,border-radius,border-image, and the longhands properties. - The
colorproperty. - The
text-decoration,text-shadow,text-transform,letter-spacing,word-spacing(when appropriate),line-height,text-decoration-color,text-decoration-line,text-decoration-style,box-shadow,float,vertical-align(only iffloatisnone) CSS properties.
As this list will be extended in the future, it is recommended that you not use any other properties inside the declaration block, in order to keep the CSS future-proof.
Example
Make the first letter of every paragraph red and big.
HTML Content
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est. Lorem ipsum dolor
sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy amet.</p>
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut
aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit
esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et
iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait
nulla facilisi.</p>
CSS Content
p::first-letter { /* Use :first-letter if support for IE 8 or earlier is needed */
color: red;
font-size: 130%;
}
first letter capital in css - ::first-letter (:first-letter)
Reviewed by JohnBlogger
on
3:33 PM
Rating:

No comments: