温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

css中的伪类有哪几种

发布时间:2021-07-23 17:35:31 来源:亿速云 阅读:115 作者:chen 栏目:web开发

这篇文章主要讲解了“css中的伪类有哪几种”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“css中的伪类有哪几种”吧!

css伪类:“:active”、“:any-link”、“:blank”、“:checked”、“:current”、“:first”、“:first-child”、“:future”、“:focus”、“:has()”、“:host”等。

本教程操作环境:windows7系统、CSS3版、Dell G3电脑。

伪类选择器(简称:伪类)通过冒号来定义,它定义了元素的状态,如点击按下,点击完成等,通过伪类可以为元素的状态修改样式。CSS伪类是用来添加一些选择器的特殊效果。

css中的伪类列表

:active:any-link:blank:checked:current:default
:defined:dir():disabled:drop:empty:enabled
:first:first-child:first-of-type:fullscreen:future:focus
:focus-visible:focus-within:has():host:host():host-context()
:hover:indeterminate:in-range:invalid:is():lang():last-child
:last-of-type:left:link:local-link:not():nth-child()
:nth-col():nth-last-child():nth-last-col():nth-last-of-type():nth-of-type():only-child
:only-of-type:optional:out-of-range:past:placeholder-shown:read-only
:read-write:required:right:root:scope:target
:target-within:user-invalid:valid:visited:where()

常用的伪类及其分类

1、动态伪类选择器

不同的状态,使用不同的样式。

  • E:link

  • E:visited

  • E:active

  • E:hover

  • E:focus

2、目标伪类选择器

用来匹配页面的URI中某个标识符的目标元素。

E:target

选择匹配E的所有元素,且匹配元素被相关URL指向。

3、语言伪类选择器

用来匹配使用指定语言的元素。

E:lang(language)

4、元素状态伪类选择器

当元素处于某种状态下时,才起作用,在默认状态下不起作用。

  • E:checked

eg:

input[type="checkbox"]:checked{}
  • E:enabled

eg:

input[type="text"]:checked{}
  • E:disabled

eg:

input[type="text"]:disabled{}

5、结构伪类选择器

这个就比较多了,平时用的也比较频繁。

  • :nth-child

  • :nth-last-child

  • :nth-of-type

  • :nth-last-of-type

  • :first-child

  • :last-child

  • :only-child

  • :first-of-type

  • :last-of-type

  • :only-of-type

  • :root 匹配元素所有在文档的根元素

  • :empty 选择没有子元素的元素,且不包含节点

6、否定伪类选择器

  • E:not(F) 匹配所有除F外的E元素

感谢各位的阅读,以上就是“css中的伪类有哪几种”的内容了,经过本文的学习后,相信大家对css中的伪类有哪几种这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css
AI