首页前端开发CSSfirst-child选择器怎么用?

first-child选择器怎么用?

时间2024-05-26 11:12:03发布访客分类CSS浏览86
导读: CSS3:first-child选择器怎么用? :first-child选择器匹配其父元素中的第一个子元素。 语法: 元素:first-child { css样式 } 例:匹配的父元素的第一个元...
  CSS3:first-child选择器怎么用?   :first-child选择器匹配其父元素中的第一个子元素。   语法:   元素:first-child   {   css样式   }   例:匹配

的父元素的第一个

元素   p:first-child   {   background-color:yellow;   }   注释:所有主流浏览器都支持:first-child选择器。对于IE8及更早版本的浏览器中的:first-child,必须声明。   CSS:first-child选择器的使用示例   示例1:选择每个

中的每个元素并设置其样式,其中的

元素是其父元素的第一个子元素:                  p:first-childi   {   background:yellow;   }            

Iamastrongman.Iamastrongman.

  

Iamastrongman.Iamastrongman.

        效果图:   1.jpg   示例2:每一个
    元素的第一个子元素选择的样式                     ul> :first-child   {   background:yellow;   }            
        
    • Coffee
    •   
    • Tea
    •   
    • CocaCola
    •   
      
        
    • Coffee
    •   
    • Tea
    •   
    • CocaCola
    •   
            效果图:   2.jpg   以上就是CSS3:first-child选择器怎么用的详细内容,更多请关注php中文网其它相关文章!


声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: first-child选择器怎么用?
本文地址: https://pptw.com/jishu/668429.html
租用香港高防服务器的好处是什么 css技术是什么?

游客 回复需填写必要信息