伪元素&伪类深度解析

伪类 伪元素区别

☀ 如果你耐着性子看完了 你就赢了

Css2中定义模糊:给某些选择器添加特殊的效果
Css3中进行了区分:
the pseudo-class is introduced to permit selection based on information that lies 
outside of the document tree or that cannot be expressed using other simple selectors

伪类作用于dom树之外的元素或者是通过简单的CSS选择器无法实现筛选的场景;
A pseudo-class always consist of a colon followed by the name of pseudo-class
and optionally by a value between parenthness
在伪类名称之前会有一个冒号:,并且还有可能含有圆括号;
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 names are case-insensitive. Some pseudo-classes are mutually exclusive
, while others can be applied simultaneously to the same element. Pseudo-classes may be dynamic,
 in the sense that an element may acquire or lose a pseudo-class while a user interacts with the document.
伪类对大小写不敏感,有些互相排斥,有些能够一起使用;

常用伪类

:active , //被激活的元素
:focus  //键盘输入焦点的元素
:hover 
:link, //未被访问的元素添加样式
:visit //已访问的链接
:first-child //元素第一个子元素
:lang //指定lang属性的元素

伪元素

css3中新增伪元素使用 ::
对于css2中定义的伪元素 仍可以使用 :
Only one pseudo-element may appear per selector, and 
if present it must appear after the sequence of simple 
selectors that represents the subjects of the selector.
一个选择器只能有一个伪元素,并且位于选择器语句的最后
  • exmple
q:lang(de)::after{
    content: " (German) ";
}
q:lang(en)::after{
    content: " (English) ";
}
q:lang(fr)::after{
    content: "(French) ";
}
q:not(:lang(fr)):not(:lang(de)):not(:lang(en))::after{
    content: " (Unrecognized language) ";
}

结果:

浏览器运行结果

其余的特殊标记例如:.. ' << ' 为浏览器自带 ::before样式

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文转载自:众成翻译译者:为之漫笔链接:http://www.zcfy.cc/article/239原文:http...
    极乐君阅读 7,412评论 1 62
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,815评论 1 92
  • CSS参考手册 一、初识CSS3 1.1 CSS是什么 CSS3在CSS2.1的基础上增加了很多强大的新功能。目前...
    没汁帅阅读 3,697评论 1 13
  • 学会使用CSS选择器熟记CSS样式和外观属性熟练掌握CSS各种选择器熟练掌握CSS各种选择器熟练掌握CSS三种显示...
    七彩小鹿阅读 6,344评论 2 66
  • 近两日园里接了教师同课异构活动,跟着看了几个活动,精彩纷呈之中,偶然有几个小环节打动人心,匆匆记录。 1.让孩子真...
    珠落玉盘a阅读 137评论 0 0