简单选择器

选择器

·简单选择器

标签选择器

p{color:blue;}

类选择器 .className

.special{color:red;}

.stress{font-weight:bold;}

-. 开头

-字母、数字、-、_

-className必须以字母开头

-区分大小写

-出现多次

id选择器 #id

#banner{color:black;}

-# 开头

-字母、数字、-、_

-id必须以字母开头

-区分大小写

-只出现一次

通配符选择器

*{color:blue;}

属性选择器

[att]

[disabled]{background-color:#eee;}

[att=val]

[type=button]{color:blue;}

id选择器其实就是属性选择器的特例

#nav{} == [id=nav]{}

[att~=val]表示属性里面包含了这么一个值,这个值以空格分隔

[class~=sports]{color:blue;}

类选择器就是这种选择器的一个特例

.sport{} == [class~=sports]{}

[att|=val]

[lang|en]{color:red;}选中lang属性等于以en或en-开头的这些元素

[att^=val]以某个值开头的属性选择器

[href^="#"]{color:red;}

[att$=val]以什么结尾的一些元素

[href$=pdf]{color:red;}

[att*=val]属性值包含某些值的

[href*="lady.163.com"]{color:pink;}

·伪类选择器

a:link{color:gray;}选中页面中所有的链接

a:visited{color:red}表示访问过的链接

a:hover{color:green}鼠标移上去的样式

a:active{color:orange}用户鼠标点击上去的样式

input:enabled{color:#ccc;}

input:disabled{color:#ddd;}

input:checked{color:#red;}

li:first-child{color:red;}

li:last-child{color:red;}

li:nth-child(even){color:red;}

li:nth-child(3n+1){color:red;}

li:nth-last-child(3n+1){color:red;}

:only-child{color:red;} 选中只有一个子元素的项

dd:first-of-type{color:red;}选中第一个这种类型的元素

dd:last-of-type{color:red;}

dd:nth-of-type(even){color:red;}

dd:nth-last-of-type(2n){color:red;}

span:only-of-type{color:red;}

:empty选中没有子元素的元素

:root选中html根标签

:not()选中不包含某个选择器的一些元素

:target选中被锚点选为目标的目标元素

:lang()选中language的值是某些特殊值的一些元素


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

推荐阅读更多精彩内容

  • 选择器 元素选择符 关系选择符 属性选择符 伪类选择符 伪对象选择符 一、元素选择符 通配选择符 (*):选择所有...
    云外之境阅读 1,892评论 0 0
  • 插入样式的三种方法 内联样式表(行内) 内部样式表(style中) 外部样式表创建一个外部样式表在head中使用l...
    Zd_silent阅读 268评论 0 0
  • 1.4.2.1简单选择器 选择器 简单选择器 伪元素选择器 组合选择器 标签选择器 类选择器 .classname...
    每日活菌阅读 359评论 0 0
  • 一、CSS选择器常见的有几种? 基本选择器 通配选择器~选择文档中所有的html元素,用一个*表示 元素选择器~选...
    dengpan阅读 977评论 0 3
  • 1.1. 属性选择器 [att*=val]选中name值包含person的input元素: [att^=val]选...
    珍珠林阅读 287评论 0 0