first-child
时间: 2023-09-24 12:05:54 浏览: 89
juqery 学习之三 选择器 子元素与表单
The `:first-child` selector is a CSS pseudo-class that selects the first child element of its parent. It is used to target an element that is the first child of another element, regardless of the element's type or class.
For example, to target the first `li` element in an unordered list, you could use the following CSS rule:
```
ul li:first-child {
/* CSS styles here */
}
```
This would select only the first `li` element within the `ul` element and apply the specified styles to that element.
Note that the `:first-child` selector only selects elements that are the first child of their parent, not elements that are the first of a certain type or class within their parent. To select the first element of a certain type or class within a parent, you would use a different selector, such as `:first-of-type` or `:nth-of-type(1)`.
阅读全文