English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
:first-child CSS pseudo-class 表示在一组兄弟元素中的第一个元素。
匹配 <p> 的父元素的第一个<p>元素
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>기본 강의(oldtoolbag.com)</title> <style> p:first-child { background-color:orange; } </style> </head> <body> <p>主体内容的第一个段落.</p> <h1>Welcome 我的个人主页</h1> <p>This paragraph is not the first child of its parent.</p> <div> <p>这是包含在Div里的第一个段落.</p> <p>这不是第一个段落.</p> </div> <p><b>주의:</b> :first-child가 IE에 영향을 미침8그리고 더 오래된 브라우저에서, DOCTYPE는 이미 선언되어야 합니다.</p> </body> </html>테스트를 보고 보세요 ‹/›
:first-child 选择器匹配其父元素中的第一个子元素。
表格中的数字表示支持该属性的第一个浏览器版本号。
选择器 | |||||
---|---|---|---|---|---|
:first-child | 4.0 | 7.0 | 3.0 | 3.1 | 9.6 |
주의: :first-child가 IE에 영향을 미침8그리고 더 오래된 IE 버전에서는 선언되어야 합니다<!DOCTYPE>
CSS 강의: CSS 伪类
选择每个 <p> 中的每个 <i> 元素并设置其样式,其中的 <p> 元素是其父元素的第一个子元素:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>기본 강의(oldtoolbag.com)</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가 IE에 영향을 미침8그리고 더 오래된 브라우저에서, DOCTYPE는 이미 선언되어야 합니다.</p> </body> </html>테스트를 보고 보세요 ‹/›
리스트의 첫 번째 <li> 요소 선택의 스타일:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>기본 강의(oldtoolbag.com)</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가 IE에 영향을 미침8그리고 더 오래된 브라우저에서, DOCTYPE는 이미 선언되어야 합니다</p> </body> </html>테스트를 보고 보세요 ‹/›
每一个<ul>元素的第一个子元素选择的样式:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>기본 강의(oldtoolbag.com)</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가 IE에 영향을 미침8그리고 더 오래된 브라우저에서, DOCTYPE는 이미 선언되어야 합니다.</p> </body> </html>테스트를 보고 보세요 ‹/›