欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
  CSS3:first-child选择器怎么用?
 
  :first-child选择器匹配其父元素中的第一个子元素。
 
  语法:
 
  元素:first-child
 
  {
 
  css样式
 
  }
 
  例:匹配<p>的父元素的第一个<p>元素
 
  p:first-child
 
  {
 
  background-color:yellow;
 
  }
 
  注释:所有主流浏览器都支持:first-child选择器。对于IE8及更早版本的浏览器中的:first-child,必须声明<!DOCTYPE>。
 
  CSS:first-child选择器的使用示例
 
  示例1:选择每个<p>中的每个<i>元素并设置其样式,其中的<p>元素是其父元素的第一个子元素:
 
  
 
  <!DOCTYPEhtml>
 
  <html>
 
  <head>
 
  <style>
 
  p:first-childi
 
  {
 
  background:yellow;
 
  }
 
  </style>
 
  </head>
 
  <body>
 
  <p>Iama<i>strong</i>man.Iama<i>strong</i>man.</p>
 
  <p>Iama<i>strong</i>man.Iama<i>strong</i>man.</p>
 
  </body>
 
  </html>





本文转载自中文网

 

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/rumen/r55970.shtml