高级前端
css
【Q339】伪类与伪元素有什么区别

伪类与伪元素有什么区别

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 342 (opens in a new tab)

Author 回答者: shfshanyue (opens in a new tab)

  1. 伪类使用单冒号,而伪元素使用双冒号。如 :hover 是伪类,::before 是伪元素
  2. 伪元素会在文档流生成一个新的元素,并且可以使用 content 属性设置内容

参考 https://www.w3.org/TR/CSS2/selector.html#pseudo-elements (opens in a new tab)