css——你不知道的伪类

1、动态伪类

 .dynamic:link {
/* 有链接 */
      /* background: red */
  }

  .dynamic:visited {
      /* 链接点击后(拜访后) */
      /* background: orange */
  }

  .dynamic:hover {
      /* 滑入 */
      /* background: blue */
  }

  .dynamic:active {
      /* 激活状态,按住不送,(有:focus的时候会被替代) */
      /* background: green */
  }

  .dynamic:focus {
      /* 聚焦后 */
      /* background: pink */
  }

2、目标伪类

p:target {
/* 突出url中某个标识符的目标元素 */
    background: yellow
}

/* input的多选被选中时 */

.element-box[type='checkbox']:checked {
    background: red
}

/* 已启用的input */

.element-input[type='text']:enabled {
    background: green
}

/* 已禁用的input */

.element-input[type='text']:disabled {
    background: yellow
}

3、语言伪类

<p lang="en">Ceci est un paragraphe.</p>
:lang(en) {
	background: red;
}

4、元素伪类选择器

 .icon::before {
  content: url('https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=591053194,1384024618&fm=26&gp=0.jpg');
    margin-right: 5px;
    vertical-align: middle
}

.welcome::before {
    content: attr(data-username)
}

5、结构伪类

.construction-box section:nth-child(4) {
/* 同级元素中所有元素第几个(如果是section的话则起作用) */
    /* color: yellow */
}

.construction-box section:nth-last-child(3) {
    /* 同级元素中所有元素倒数第几个 (如果是section的话则起作用)*/
    /* color: red */
}

.construction-box section:nth-of-type(4) {
    /* 同级元素中(相同)元素第几个 */
    /* color: red */
}

.construction-box section:nth-of-type(1) {
    /* 同级元素中(相同)元素倒数第几个 */
    /* color: red */
}

/* .construction-box section:first-child {
    color: red
}

.construction-box section:last-child {
    color: yellow;
} */

.construction-box section:only-child {
    /* 同级只有一个元素且是section */
    /* color: red */
}

.construction-box section:only-of-type {
    /* 同级只有一个section元素时 */
    /* color: red */
}
:root {
    /* 匹配元素所有在文档的根元素 */
    /* color: yellowgrepen */
}

.construction-box p:empty {
    /* 空的 */
    /* height: 20px;
    background: #ff0000; */
}

6、排除伪类

 .construction-box section:not(.aaa) {
 /* 排除指定的*/
      color: red
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值