引用文本内容自《CSS选择器世界》css选择器辨别(空格)后代选择器优先级相同,排在后面document.querySelector('#myId').querySelectorAll(':scopedivdiv')>sub-main目的:避免冲突场景:状态类名控制,标签限制,层级位置和动态判断+邻接兼容IE8实现:first-child~后跟之前的实现:visualfirst,dom||之后列跨列td选择选择器模式amcss[am-button~="large"]{}规定:start[attr^="val"];结束[attr$="val"];contain[attr*="val"]忽略大小写[attr~="val"i]搜索过滤css选择器最佳实践小写、短命名、相同前缀组合'-'命名<5;面向属性,语义化(html标签,属性,伪类)命名不要驼峰命名,id,嵌套,标签,*selector状态类名:.active本身没有样式样式类型:reset,base,interactivechange/*website变量*/:root{--base-color:#4c5161;}/*样式重置*/body,p,dd,dl,h1,...,ol,ul{margin:0}/*一般结构*/.cs-header{}.cs-main{}.cs-footer{}/*组件样式*/.cs-icon{}.cs-button{}.cs-dialog{}/*模块样式*/.cs-module-header{}.cs-module-title{}.cs-module-x{}/*业务样式*/.cs-some-.../*css样式库*/.dn{display:none}.db{显示:块}。dib{display:inline-block}.fl{float:left}伪类用户行为:hover不适用于移动端;增加延迟优化体验;:active支持任何元素;数据报告;样式技巧:box-shadow、linear-gradient、outline;:focus非禁用表单元素,href的、,contenteditable常用元素;鼠标传递行为的键盘访问:focus-within:focus当负责元素或任何子元素获得焦点时;下拉列表;hover,:activepriority:LVHA:any-link::link对访问过的无效,只对:targetanchor有效;scene:expandandcollapse,tab:target-withintargetordescendantelements,目前暂时不支持input:enabledand:disabled下chromeenable影响a,ie下的fieldset不支持,contenteditable="true"不匹配:read-only和:read-write:readonly可以通过表单提交,disabled不能;:placeholder-shown场景:材质样式;空值判断;:defaultselectedcheckedmustbetrue场景:将支付方式标记为“推荐”:checked只能是form,[checked]是任意的,变化不是实时的;阅读更多;标签;单个复选框,开关;:不确定复选框。不确定=真;单选不选所有名字时匹配,不选名字时匹配;提示文案未选中;输入值验证:有效和无效(:user-invalid:blank还不支持):in-rangeand:out-of-range:requiredand:optional:user-invalidand:blanktreestructure:root文档根元素,xhtml、svgShadowDOM不起作用。root负责css变量,html负责样式:empty前后可以有注释,换行不能有空格。场景:隐藏空元素,缺失字段提示子索引:first-child:last-child:only-child没有任何兄弟元素:nth-??child()只适用于动态内容,支持odd,even,An+B;:nth-last-child()动态列表号匹配(聊天群头像)li:only-child{}li:first-child:nth-last-child(2){}匹配类型:first-of-typeandlast-of-type:only-of-type:nth-??of-type()和nth-last-of-type()逻辑组合:not():is()简化.is(.cs-a,.cs-b)>img:where()效果相同,但优先级始终为0其他:hostShadowDOM根元素:host()ShadowDOM根元素匹配伪类:host-context()ShadowDOM根元素上下文匹配伪类:fullscreenfullscreen:dir(ltr|rtl)direction:lang()language:playing:pausedaudio元素
