css 伪类与伪元素 css伪元素::before与::after使用基础示例

  • css伪类

css伪类用于向某些选择器添加特殊的效果。
:link, :visited, :hover, :focus, :active, :first-child, :lang
css3新增的伪类:
:last-child, :only-child, :first-of-type, :last-of-type, :only-of-type, :nth-child(n), :nth-last-child(n), :nth-of-type(n), :nth-last-of-type(n), :root, :empty, :target, :enabled, :disabled, :checked, :not(selector),

  • css伪元素

css伪元素用于向某些选择器设置特殊效果。
::first-letter, ::first-line, ::before, ::after
css3新增的伪元素
::selection

css伪类和伪元素的区别

伪类可以叠加使用,而伪元素在一个选择器中只能出现一次,并且只能出现在末尾

为了避免大家混淆伪类和伪元素,css3中的标准规定伪类使用单冒号“:” ,伪元素使用双冒号“::”,但在此之前都使用的单冒号“:”,所以为了保证兼容伪元素两种使用方法都是可以的。

伪类与类优先级相同,伪元素与标签优先级相同。顺便说一下优先级怎么判断,一般是 !important > 行内样式> ID选择器 > 类选择器 > 标签 > 通配符 > 继承 > 浏览器默认属性


链接:https://www.jianshu.com/p/7d86345ac877

css伪元素::before与::after使用基础示例

1.指定文本前后添加内容

文字前后自动加上引号

相片堆叠

简单实现一个聊天气泡

猜你喜欢

转载自www.cnblogs.com/-constructor/p/12298338.html