CSS高级选择器

本文详细介绍了CSS中的first-of-type、last-of-type、only-of-type、first-child和last-child选择器,以及before和after伪元素的使用方法。同时,讨论了CSS优先级算法,明确了!important、id、class和标签选择器的权重。此外,还提到了HTML5表单中的email和url输入类型,它们在提交时能自动验证输入值的有效性。
摘要由CSDN通过智能技术生成

1.

p:first-of-type{

            background: red;}

p:first-of-type 选择属性其父元素的首个p元素的每个<p>元素

p:last-of-type{

            background: red

        }

p:last-of-type选择属性其父元素的最后p元素的每个p元素

 p:only-of-type{

            background:red;

        }

p:only-of-type  选择属于其父元素唯一的p 元素的每个p元素

p:first-child{

            background: red;

        }

p:first-child选择属性其父元素第一个子元素的每个p元素

p:last-child{

            background: red;

        }

p:last-child选择属性其父元素最后一个子元素的每个p元素

 p:nth-of-type(1){

            background-color: red;

  p:before{

        content:'前面插入的内容';

            color:red;

        }

content表示文字内容。p:before表示在每个<p>元素的内容之前插入内容

p:after{

       content:'后面插入的内容';

            color:blue;}

content表示文字内容 。p:after在每个<p>元素的内容之后插入内容

2.优先级算法

优先级就近原则,同权重情况下样式定义最近者为准。

 !important > id选择器 > class类选择器 > tag标签选择器。

         !important infinity(无穷大)

        行内样式    1000

        id选择器    100

        class类选择器|属性选择器|伪类  10

        标签选择器   1

        通配符(*)    0

3.

   电子邮件: <input type="email" name="emilName">   提交表单时会自动验证email的值

   网页的URL: <input type="url" name="urlName">   提交表单时会自动验证url的值

   选取颜色:<input type="color" name="colorName">

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值