
属性选择器
Element[attr ^= “value” ] 属性以字符串开头
Element[attr $= “value” ] 属性以字符串开头
Element[attr ~= “value” ] 属性以字符串开头
伪类选择器
:root 的优先级大于 html
:hover
:not([textIndent $= “first”]) 查找textIndent 不是以first结尾的元素
:not([textIndent ^= “first”]) 查找textIndent 不是以first开头的元素
:not 中选择器的权重问题
:not (div > a) 非div下的a
:empty 选择器 查找 真正是空的元素 内部没有任何文本节点
:target 用户选中某个锚点之后 将找到的那个元素应用上特定的样式
:nth-child(an + b)以a为循环的个数,b为基数
:first-child 查找相同级别下面第一次出现的元素
- 结构选择器:
- 属性选择器
- Element[attr ^= “value” ] 属性以字符串开头
- Element[attr $= “value” ] 属性以字符串开头
- Element[attr ~= “value” ] 属性以字符串开头
- 伪类选择器
- :nth-child
- :nth-of-type
- :not
- :target
- :empty
- 属性选择器
- UI元素状态伪类选择器
- :active
- :hover
- :focus
- :enabled
- :disabled
- :read-only 只读
- :read-write 可读写
- :checked 选中状态
- :default 当前浏览器被打开的时候当前被指定的默认样式是什么。
- :indetermate
- :first-letter 必须是块级元素
- :first-line 必须是块级元素
- 关系选择器
- E F 后代选择器
- E > F 直接子元素选择器
禁用 disabled
只读 readonly
在表单中的唯一作用就是 readonly 可以被提交 disabled不会被提交.
readonly选择器的值会覆盖disabled
read-write 可以作用于disabled
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>选择器</title><style>/* :not(div > a) {color: aquamarine;} *//* 空 */.box{width: 100px;height: 100px;background-color: brown;color: #fff;}.box:empty{color: #000;background-color: blue;}/* 用户选中某个锚点之后 将找到的那个元素应用上特定的样式 */:target{background-color: black;}p:nth-child(4n + 1){background-color: #aaa;}p:nth-child(4n + 2){background-color: blue;}p:nth-child(4n + 3){background-color: purple;}p:nth-child(4n + 4){background-color: chartreuse;}p:nth-child(4n + 5){background-color: salmon;}/* nth-child */div.last :first-child{background-color: red;}/* nth-of-type */div.last :first-of-type{background-color: salmon;}.box2 :only-child{color: salmon;}/* UI元素状态伪类选择器 */.box3 > input:hover{color: salmon;}.box3 > input:focus{color: salmon;}/* 鼠标按住不动的颜色 */.box3 > input:active{color: blue;}.box3 > input:disabled{background-color: #aaa;}.box3 > input:enabled{background-color: #fff;}.box3 > input:read-only{background-color: #ccc;color: red;outline: none;border: none;}.box3 > input:read-write{background-color: green;}.box3 > input[type = "radio"]:checked{outline: 2px solid #000;}.box3 > input[type = "radio"]:default{outline: 0px solid #000;}.box3 > input[type = "checkbox"]:checked{outline: 2px solid #000;}.box3 > input[type = "checkbox"]:default{outline: 10px solid #000;}/* indeterminate 不确定 */.box4 > :indeterminate :indeterminate + label{background-color: greenyellow;}.box5 > p::first-letter{color: red;font-size: 18px;text-transform: uppercase;}.box5 > :nth-of-type(2)::first-line{color: red;}.box5 > p::selection{color: forestgreen;background-color: gold;}/* 直接子元素选择器*/.box6 > span{color: gold;}span {color: green;}/* */</style></head><body><h1>:not</h1><a href="">我是非table下的a</a><table><a href="">我是table下的a</a><tr><td> <a href="">td下的a</a></td></tr></table><div><a href="">我是div下的a</a></div><!-- empty --><hr><h1>empty</h1><div class="box"><hr><!-- 我是换行的注释节点 --></div><div class="box"><!-- 我是注释节点 --></div><div class="box">我是普通文本节点</div><hr><h1>锚点选择器</h1><!-- 锚点选择器 --><div id="one">one</div><div id="two">two</div><div id="three">three</div><div id="four">four</div><a href="#one">one</a><a href="#two">two</a><a href="#three">three</a><a href="#four">four</a><hr><h1>nth-child</h1><!-- nth-child --><p>1</p><p>2</p><p>3</p><p>4</p><p>5</p><p>6</p><p>7</p><p>8</p><hr><!--/* nth-of-type */div.last :first-of-type{background-color: salmon;}--><h1>nth-of-type</h1><div class="last"><span>这是span1</span><span>这是span2</span><span>这是<em>嵌套em的span</em></span><span>这是<span>嵌套span</span>的span</span><em>这是em</em><span>这个是最后一个span</span></div><!-- only-child --><hr><h1>only-child</h1><div class="box2"><div><i>只有一个子元素</i></div><div><i>我是第一个子元素</i><em>我是em标签</em><span>我有一个<span>span</span></span></div></div><hr><h1>a标签伪类</h1><a href="">这个是a标签</a><input type="text"><!-- UI元素状态伪类选择器 --><hr><h1>UI元素状态伪类选择器</h1><div class="box3"><input type="text" value="enabled" enabled/><input type="text" value="disabled" disabled/><input type="text" value="read-only" readonly/><input type="text" value="read-write" readwrite /><input type="radio" /><input type="checkbox" id="read" checked disabled/><label for="read">read</label><input type="checkbox" id="tourist"/><label for="tourist">tourist</label></div><hr><h1>indeterminate</h1><div class="wrap"><div class="box4"><input type="checkbox" id="radio"><label for="radio">radio</label></div><div class="box4"><input type="checkbox" id="checkbox" checked><label for="checkbox">checkbox</label></div></div><hr><h1>first-letter</h1><div class="box5"><p class="test">这是为了测试这是为了测试这是为了测试这是为了测试这是为了测试</p><p class="test">这是为了测试这是为了测试这是为了测试这是为了测试这是为了测试</p><p class="test">today is a nice daytoday is a nice daytoday is a nice daytoday is a nice daytoday is a nice day</p></div><hr><h1>后代选择器</h1><div><span></span></div><hr><h1>直接后代选择器</h1><div><span><span>我是span里面的span</span></span></div><script>var oInputs = document.getElementsByClassName('wrap')[0].querySelectorAll("input");oInputs.forEach(item=>{item.indeterminate = true;})</script></body></html>
