有些时候咱们会遇到在元素之间设置间隔的需求,margin-left、margin-right或者border-top、border-bottom等,这时候就须要选择不为第一个元素添加样式或者不给最后一个元素添加样式。css
不选择第一个元素样式的代码是:code
div: nth-child(n+1){ margin-left: 10px; }
不选择最后一个元素的代码,须要用到not:ast
/*能够不用这么长;这个也能写不选择第一个元素*/ div: nth-child(n):not(:last-child){ margin-right: 10px; }
not选择符的效果就是在普通css选择器的基础上再作一个差运算吧(我猜)class
not有一些限制,括号中只能写一些简单的选择符(元素选择符、*、类、id、伪类),咱们上面用到的伪类选择符算是最复杂的了。基础
多个not不能连起来用。css选择器