面试题:CSS伪类选择器有哪些?CSS3新增的伪类选择器有哪些?

CSS伪类选择器:

a:link 没有访问之前a标签的样式

a:visited 已访问a标签的样式

a:hover a标签鼠标移上的样式

a:actived a标签鼠标按下的样式

input:focus input表单元素获取焦点

input:blur input表单元素失去焦点

CSS3新增的伪类选择器:

:checked 被选中 主要用在input表单元素上

:not 排除

:last-child 最后一个元素

:nth-child(n)  n表示具体的第几个  odd/2n+1 奇数 even/2n 偶数

:only-child 仅仅/唯一的元素

:nth-last-child(n) 倒数第几个元素  :nth-last-child(1) <=> :last-child

:first-of-type 第一个同级兄弟元素

:last-of-type 最后一个同级兄弟元素

:only-of-type 只有一个同级兄弟元素

:nth-of-type(n) 第几个同级兄弟元素

:nth-last-of-type(n) 倒数第几个同级兄弟元素

:empty 空内容

<style> 
    ul li{
        float: left;
        list-style: none;
        width: 100px;
        height: 50px;
        background: red;
    }
    /* 排除最后一个li没有右边框线 其余都有,排除了内容为$3的li */
    ul li:not(:last-child){
        border-right: 10px solid #000;
    }
    /* 第一个li背景元素为blue,改变的是内容为$1的li的样式 */
    ul li:nth-child(1){
        background-color:blue;
    }
    /* 偶数位背景元素为yellow,改变的是内容为$2的li的样式 */
    ul li:nth-child(even){
        background-color:yellow;
    }  
    /* ul只有一个li子元素,改变的是内容为$4的li的样式 */
    ul li:only-child{
        background-color: green;
    }
</style>

<ul>
    <li>$1</li>
    <li>$2</li>
    <li>$3</li>
</ul>
<ul>
    <li>$4</li>
</ul>

<style>
    p:first-of-type{
        background-color: red;
    }
    p:last-of-type{
        background-color: yellow;
    }
    p:only-of-type{
        background-color:blue;
    }
    p:nth-of-type(2){
        background-color: green;
    }
    p:nth-last-of-type(3){
        background-color: purple;
    }
    p:empty{
        height: 20px;
        background-color: orange;
    }
</style>

<div>我是一个div元素</div>
<p>我是一个p元素</p>
<p>我是一个p元素</p>
<p>我是一个p元素</p>
<p></p>
<p>我是一个p元素</p>
<div>
  <p>我是一个p元素</p>
</div>

转载于:https://www.cnblogs.com/youknowUL/p/11416257.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值