This topic has not yet been rated - Rate this topic

:first-child

Applies one or more styles to any element that is the first child of its parent.

:first-child { sRules }

sRules

Value that specifies one or more cascading style sheets attribute/value pairs.

The :first-child pseudo-class matches an element that is the first child element of some other element.

Inline text is not considered to be part of the document tree, and is not counted when calculating the first child. For example, the EM element is the first child of the P element in the following HTML code:

<p>abc <em>default</em> def</p>

In the following example, the selector matches any P element that is the first child of its parent (the style rule suppresses indentation for the first paragraph only):

<style>
    p:first-child {text-indent: 0}
</style> 

The preceding selector would match the P element inside the DIV of the first fragment that follows, but would not match the P element in the second fragment:

<!-- First fragment -->
<div class="note">
   <p> The first P inside the note. </p>
</div>
<!-- Second fragment -->
<div class="note">
   <h2>Note</h2>
   <p> The first P inside the note. </p>
</div>

A, ABBR, ACRONYM, ADDRESS, B, BIG, BLOCKQUOTE, BODY, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, DD, DFN, DIV, DL, DT, EM, FORM, HN, HTML, I, IMG, INPUT, INPUT TYPE=BUTTON, INPUT TYPE=CHECKBOX, INPUT TYPE=FILE, INPUT TYPE=HIDDEN, INPUT TYPE=IMAGE, INPUT TYPE=PASSWORD, INPUT TYPE=RADIO, INPUT TYPE=RESET, INPUT TYPE=SUBMIT, INPUT TYPE=TEXT, LI, OL, P, S, SELECT, SPAN, SUB, TABLE, TBODY, TD, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.