小白教程
所有教程
关于
Search
172.70.130.238
172.70.130.238
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Sel firstchild”的源代码
本页内容
上一节:
Sel_firstline
下一节:
Sel_before
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE::first-child}}[[Category:css selectors|20]] = CSS :first-child 选择器 = [[css selectors|完整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:yellow; } </style> </head> <body> <p>This paragraph is the first child of its parent (body).</p> <h1>Welcome to My Homepage</h1> <p>This paragraph is not the first child of its parent.</p> <div> <p>This paragraph is the first child of its parent (div).</p> <p>This paragraph is not the first child of its parent.</p> </div> <p><b>注意:</b> :first-child作用于 IE8以及更早版本的浏览器, DOCTYPE必须已经声明.</p> </body> </html> </run> == 定义和用法 == :first-child 选择器匹配其父元素中的第一个子元素。 == 浏览器支持 == 表格中的数字表示支持该属性的第一个浏览器版本号。 {| class="table table-striped table-hover" ! 选择器 ! Chrome ! Internet Explorer / Edge ! Firefox ! Safari ! Opera |- | :first-child | 4.0 | 7.0 | 3.0 | 3.1 | 9.6 |} '''注意:''' :first-child在IE8和更早版本IE版本中必须声明[[tag doctype|<!DOCTYPE>]] == 相关文章 == CSS 教程: [[css pseudo classes|CSS 伪类]] == 更多实例 == 选择每个 <p> 中的每个 <i> 元素并设置其样式,其中的 <p> 元素是其父元素的第一个子元素: <sample title="" desc="" lang="html" hererun="1"> p:first-child i { background:yellow; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> p:first-child i { background:yellow; } </style> </head> <body> <p>I am a <i>strong</i> man. I am a <i>strong</i> man.</p> <p>I am a <i>strong</i> man. I am a <i>strong</i> man.</p> <p><b>注意:</b> :first-child作用于 IE8以及更早版本的浏览器, DOCTYPE必须已经声明.</p> </body> </html> </run> 列表中的第一个 <li>元素选择的样式: <sample title="" desc="" lang="html" hererun="1"> li:first-child { background:yellow; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> li:first-child { background:yellow; } </style> </head> <body> <ul> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ul> <ol> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ol> <p><b>注意:</b> :first-child作用于IE8以及更早版本的浏览器, DOCTYPE必须已经声明</p> </body> </html> </run> 每一个<ul>元素的第一个子元素选择的样式:: <sample title="" desc="" lang="html" hererun="1"> ul>:first-child { background:yellow; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> ul>:first-child { background:yellow; } </style> </head> <body> <ul> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ul> <ul> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ul> <p><b>注意:</b> :first-child作用于 IE8以及更早版本的浏览器, DOCTYPE必须已经声明.</p> </body> </html> </run> [[css selectors|完整CSS选择器参考手册]]
返回至“
Sel firstchild
”。
上一节:
Sel_firstline
下一节:
Sel_before