“Sel firstchild”的版本间差异
本页内容
(创建页面,内容为“{{DISPLAYTITLE::first-child}}8 = CSS :first-child 选择器 = 完整CSS选择器参考手册 匹配 <p> 的父元素的第一个<p>元素 <sample title="" desc="" lang="html" hererun="1"> p:first-child { background-color:yellow; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> p:first-child { background-color…”) |
无编辑摘要 |
||
(未显示同一用户的2个中间版本) | |||
第1行: | 第1行: | ||
{{DISPLAYTITLE::first-child}}[[Category:css | {{DISPLAYTITLE::first-child}}[[Category:css selectors|20]] | ||
= CSS :first-child 选择器 = | = CSS :first-child 选择器 = | ||
2022年8月19日 (五) 04:50的最新版本
CSS :first-child 选择器
匹配 <p> 的父元素的第一个<p>元素
示例
p:first-child
{
background-color:yellow;
}
定义和用法
- first-child 选择器匹配其父元素中的第一个子元素。
浏览器支持
表格中的数字表示支持该属性的第一个浏览器版本号。
选择器 | Chrome | Internet Explorer / Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
:first-child | 4.0 | 7.0 | 3.0 | 3.1 | 9.6 |
注意: :first-child在IE8和更早版本IE版本中必须声明<!DOCTYPE>
相关文章
CSS 教程: CSS 伪类
更多实例
选择每个 <p> 中的每个 <i> 元素并设置其样式,其中的 <p> 元素是其父元素的第一个子元素:
示例
p:first-child i
{
background:yellow;
}
列表中的第一个 <li>元素选择的样式:
示例
li:first-child
{
background:yellow;
}
每一个<ul>元素的第一个子元素选择的样式::
示例
ul>:first-child
{
background:yellow;
}