如果有 3 个 div,我只想定位一个规则,如果有 4 个 div,我想定位另一个规则。
标记
//one set of rules
<div></div>
<div></div>
<div></div>
//second fules
<div></div>
<div></div>
<div></div>
<div></div>
CSS
/* three items */
div:nth-child(1):nth-last-child(3),
div:nth-child(2):nth-last-child(2),
div:nth-child(3):nth-last-child(1)
/* fouritems */
div:nth-child(1):nth-last-child(4),
div:nth-child(2):nth-last-child(3),
div:nth-child(3):nth-last-child(2),
div:nth-child(4):nth-last-child(1)
我遵循了这个: http: //lea.verou.me/2011/01/styling-children-based-on-their-number-with-css3/但不幸的是运气不佳。