分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

CSS常用属性之选择器

发布时间:2023-09-06 01:37责任编辑:沈小雨关键词:CSS选择器

css选择器

序号选择器例子例子描述
1.class.intro选择class="intro"的所有元素
2#id#firstname选择id="firstname"的元素
3elementp选择所有<p>元素
4element,elementdiv,p选择所有<div>元素和所有<p>元素
5element elementdiv p选择<div>元素内部的所有<p>元素
6element>elementdiv>p选择父元素为<div>元素的所有<p>元素
7[attribute][target]选择带有target属性所有元素
8[attribute=value][target=_blank]选择target="_blank"的所有元素
9[attribute~=value][title~=flower]选择title属性包含单词"flower"的所有元素
10[attribute|=value][lang|=en]选择lang属性值以"en"开头的所有元素
11:linka:link选择所有未被访问的链接
12:visiteda:visited选择所有已被访问的链接
13:activea:active选择活动链接
14:hovera:hover选择鼠标指针位于其上的链接
15:focusinput:focus 选择获取焦点的input元素 
16:first-letterp:first-letter选择每个元素的首字母
17:first-linep:first-line选择每个<p>元素的首行
18:beforep:before在每个<p>元素的内容之前插入内容
19:afterp:after在每个<p>元素的内容之后插入内容
20:lang(language)p:lang(it)选择带有以"it"开头的lang属性值的每个<p>元素
21element1~element2p~ul选择前面有<p>元素的每个<ul>元素
22[attribute^=value]a[src^="https"]选择其src属性值以"https"开头的每个<a>元素
23[attribute$=value]a[src$=".pdf"]选择其src属性以".pdf"结尾的所有<a>元素
24:first-of-typep:first-of-type选择属于父元素里面的首个<p>元素
25:last-of-typep:last-of-type选择属于父元素里面的最后一个<p>元素
26:only-of-typep:only-of-type选择父元素里面只有一个<p>元素
27:only-childp:only-child选择父元素只有一个子元素的<p> 元素
28:nth-child(n)p:nth-child(2)选择属于其父元素里面的第二个子元素<p>(索引从1开始)
29:nth-last-child(n)p:nth-last-child(2)同上,从最后一个元素开始计数
30:nth-of-type(n)p:nth-of-type(2)选择属于其父元素的二个<p>元素的每个<p>元素
31:nth-last-of-type(n)p:nth-last-of-type(2)同上,但是从最后一个元素计数
32:last-childp:last-child选择属于其父元素最后一个子元素每个<p>元素
33:root:root选择文档的根元素
34:emptyp:empty选择没有子元素的每个<p>元素(包括文本节点)
35:target#news:target选择当前活动的元素
36:enabledinput:enabled选择每个启用的<input>元素
37:disabledinput:disabled选择每个被禁用的<input>元素
38:checkedinput:checked选择每个被选中的<input>的元素
39:not(selector):not(p)选择非<p>元素的每个元素
40::selection::selection选择被用户选取的元素部分
    

CSS常用属性之选择器

原文地址:https://www.cnblogs.com/litings/p/8312910.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved