not

:not选择器 解决消失的边界线问题
image.png

  1. /* 去掉边框 */
  2. .nav li:last-child {
  3. border-right: none;
  4. }
  5. 不过不要这么做,使用 :not() 伪类来达到同样的效果:
  6. .nav li:not(:last-child) {
  7. border-right: 1px solid #666;
  8. }

同级变淡
// 选择一个没有href、target、rel属性的标签
a:not([href]):not([target]):not([rel]){
border: 1px solid blue;
}

hover+not

image.png

负nth-child

负的nth-child

li {
  display: none;
}

/* 选择第 1 至第 3 个元素并显示出来 */
li:nth-child(-n+3) {
  display: block;
}
或许你已经掌握了如何使用 :not()这个技巧,试下这个:

/* 选择除前3个之外的所有项目,并显示它们 */
li:not(:nth-child(-n+3)) {
  display: none;
}

猫头鹰选择器