单个标签 直接使用标签名
多个标签 复杂选择器
div p 选择div内部的全部p元素
div > p 父元素为div的全部p元素
li + li 紧接在li以后的li元素
p ~ ul 选择前面有p元素的每一个ul元素css
好比对多个li添加下划线
可直接使用html
ul li+li{ border-top:1px solid #ccc; }
id/class选择器 略过布局
input[type='text']{ }
a:link a:hover a:activted a:visited
a标签的四个伪类排列顺序和缘由spa
link指有连接属性时 visited 连接地址已经被访问过 active 被用户激活 hover鼠标悬停code
根据使用情景肯定a状态htm
缘由:link和visited为静态常态,但一旦被访问应该覆盖原样式
在鼠标操做时,a标签同时具有hover 和active 状态 因此active必须放在hover以后element
table tr:nth-child(even){} table tr:nth-child(odd){} table tr:first-child{} table tr:last-child{} table tr:nth-child(2n+1)
:before 和 :after很是经常使用
例如:input
<style> span:before{ content:'你好,' } span:after{ content:'!' } </style> <span>Shirly</span>
使用注意:it
尽可能对外层添加class, 内层使用多级选择器,下降初步布局样式的优先级以便js处理table
首先明确选择器表达式的重要程度。
公式: I-C-E
I–id —–C-class —— E-element
遇到一个id就往特指度数值中加100,遇到一个class就往特指度数值中加10,遇到一个element就往特指度数值中加1
还有一个重点要注意:!important优先级最高,高于上面一切。* 选择器最低,低于一切。
box-sizing:border-box;
纵向的margin会重叠,值较大的覆盖掉较小的。
div{ border:10 solid; border-color:#444 transparent transparent transparent ; width:0; }