伪类(:)和伪元素(::)的区别

本文详细介绍了CSS中的伪类和伪元素,解析了它们在CSS2和CSS3中的定义和区别。伪类用于选取DOM树中不存在的信息,如`:link`、`:visited`,而伪元素如`::before`、`::after`创建了虚拟容器,可包含内容。CSS3中,伪类使用单冒号表示,伪元素用双冒号表示,但为兼容性,CSS2伪元素仍可用单冒号。
摘要由CSDN通过智能技术生成

伪类和伪元素都是CSS1和CSS2中的概念,CSS1和CSS2中对伪类的伪元素的区别比较模糊,CSS3才对这两个概念做了相对较清晰的概念,下面看看css2和css3中对这两个概念的定义:

伪类 - pseudo classes

CSS2中对伪类的定义:

CSS 伪类用于向某些选择器添加特殊的效果。

单单看定义看不懂在讲什么。
CSS3对伪类的定义:

The pseudo-class concept is introduced to permit selection based on information that lies outside of the document tree or that cannot be expressed using the other simple selectors.

A pseudo-class always consists of a “colon” (:) followed by the name of the pseudo-class and optionally by a value between parentheses.

Pseudo-classes are allowed in all sequences of simple selectors contained in a selector. Pseudo-classes are allowed anywhere in sequences of simple selectors, after the leading type selector or universal selector (possibly omitted). Pseudo-class nam

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值