Matt Mastracci 介绍了如何以有趣的方式组合现有的位置选择器,以创建您可能从未想到过的逻辑。例如,选择所有元素,仅当它们有五个,使用
span:first-child:nth-last-child(5),
span:first-child:nth-last-child(5) ~ span {
/* select the span if its BOTH first and 5th from the end, then all spans after it. */
}
其用处在于应用特殊的布局以适应未知的标记。
让我想起了我看到 Estelle Weyl 做的一个旧的 CSS 技巧,她可以在不知道有多少列的情况下完美地调整列大小。