:first-child
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 7ì.
* Some parts of this feature may have varying levels of support.
CSS :first-child ìì¬ í´ëì¤ë íì ìì ì¤ ì ì¼ ì²« ìì를 ëíë
ëë¤.
css
/* Selects any <p> that is the first element
among its siblings */
p:first-child {
color: lime;
}
ì°¸ê³ : ì´ê¸° ì ìììë ë¶ëª¨ê° ìë ììë§ ì íí ì ìììµëë¤. Selectors Level 4ë¶í°ë ì´ ì íì´ ì¬ë¼ì¡ìµëë¤.
구문
Error: could not find syntax for this itemìì
>기본 ìì
HTML
html
<div>
<p>This text is selected!</p>
<p>This text isn't selected.</p>
</div>
<div>
<h2>This text isn't selected: it's not a `p`.</h2>
<p>This text isn't selected.</p>
</div>
CSS
css
p:first-child {
color: lime;
background-color: black;
padding: 5px;
}
ê²°ê³¼
ëª©ë¡ ì¤íì¼ë§
HTML
html
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>
Item 3
<ul>
<li>Item 3.1</li>
<li>Item 3.2</li>
<li>Item 3.3</li>
</ul>
</li>
</ul>
CSS
css
ul li {
color: blue;
}
ul li:first-child {
color: red;
font-weight: bold;
}
ê²°ê³¼
ëª ì¸
| Specification |
|---|
| Selectors Level 4 > # first-child-pseudo > |