批改状态:合格
老师批语:写的不错
id:千位class:百位tag:个位一个标签:css选择器权重为(0,0,1)一个标签加一个class: css选择器权重为(0,1,1)一个标签加一个class加一个id: css选择器权重为(1,1,1)(1,1,1)>(0,1,1)>(0,0,1)同级时按书写顺序,后面覆盖前面!不同级时,按照权重计算!!important为最高指示,忽略任何权重,属于调试样式

div{color: chartreuse;}

div > pre{color: red;}

div.selector > pre{color: green;}

div.selector#selectorid > pre{color: blue;font-weight:bolder;}

div >pre {color: blueviolet !important;}
伪类an+b 计算方式a系数:一个是0,一组是1n变量:[0,1,2,3....]b:偏移量

/* 匹配第三个an+3,因为a=0,0n+3=3*/.list > :nth-of-type(3){background-color: aqua;}

/* 选取全部匹配一组a=1 n=[0,1,2,3....]a*n1*0 01*1 11*2 21*3 3...[1,2,3....]*/.list > :nth-of-type(n){background-color: aqua;}

/*第三个元素后面所有元素 n+3 n=[0,1,2,3...]0+3 31+3 42+3 5...*/.list > :nth-of-type(n+3){background-color: aqua;}

/*取前三个-n+3 n=[0,1,2,3...]-0+3 3-1+3 2-2+3 1*/.list > :nth-of-type(-n+3){background-color: aqua;}

/*最后三个 换下选择器就可以 */.list > :nth-last-of-type(-n+3){background-color: aqua;}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号