CSS :first-child pseudo-class
- Baya na zuwa :first
- Baya na sau :first-of-type
- Raba samfuran CSS pseudo-class reference bukata
Definition and usage
CSS :first-child
Pseudo-classes are used to select elements that are the first child of their parent element (in a group of sibling elements).
Example
Example 1
Select and set the style of each <p> element that is the first child of its parent element:
p:first-child { background-color: yellow; }
Example 2
Select and set the style of each <i> element that is the first child of its parent element:
i:first-child { background: yellow; }
Example 3
Select and set the style of the first <li> element in the list:
li:first-child { background: yellow; }
Example 4
Select and set the style of the first child of each <ul> element:
ul > :first-child { background: yellow; }
CSS Grammar
:first-child { css declarations; }
Technical details
Version: | CSS3 |
---|
Tabbatar da browsers
Tabbinen daɗiya ce ke tabbatar da tsarin yauyuka na wannan maganar a fagen farko.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
4.0 | 7.0 | 3.0 | 3.1 | 9.6 |
Shafin samfuran da yake da alama
Tarin CSS:类伪类 CSS
- Baya na zuwa :first
- Baya na sau :first-of-type
- Raba samfuran CSS pseudo-class reference bukata