Skip to content

[css] 第91天 CSS的伪类和伪对象有什么不同? #758

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

第91天 CSS的伪类和伪对象有什么不同?

Activity

HuoXiaoYe

HuoXiaoYe commented on Jul 16, 2019

@HuoXiaoYe
  • 伪类:我们常用的比如,hover,focus等,我认为伪类是为了弥补选择器的不足。还有伪类选择器,比如first-child,nth-child.
  • 伪元素 : ::before ::after 是为了创建一个dom元素,使用content属性指定要插入的内容。content必须有值(空值也行)。还有 伪元素选择器,比如 first-line first-letter
xiangshuo1992

xiangshuo1992 commented on Jul 16, 2019

@xiangshuo1992
Contributor

关于伪元素,之前已经有比较多的讨论了。
#39
#63

NicholasBaiYa

NicholasBaiYa commented on Jul 16, 2019

@NicholasBaiYa

伪类是给当前选中节点添加新样式,
伪对象是给当前选中节点添加伪元素。
伪类选择器使用:,伪对象选择器使用::,因为兼容旧版,所以伪对象使用:也能解析。

nowherebutup

nowherebutup commented on Jul 16, 2019

@nowherebutup
  • 伪类:描述元素的状态,以及用于css选择器
  • 伪元素: 为元素增加子元素,DOM上没有,逻辑存在,一般用于清除浮动,设置子元素...
Konata9

Konata9 commented on Aug 22, 2019

@Konata9

伪类是控制元素的行为(:hover, :active, :visited, :focus),当在某个行为下这个元素会呈现什么样式。

伪元素则是一个原本不存在 DOM 上的元素(::before, ::after),必须要设置 content 属性才会生效。

关联回答:

  • [Day13]
  • [Day5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@Konata9@xiangshuo1992@NicholasBaiYa@nowherebutup

        Issue actions

          [css] 第91天 CSS的伪类和伪对象有什么不同? · Issue #758 · haizlin/fe-interview