有时需要判断同级别,元素的数量
根据不同的数量,显示不同的样式,一般这种需求需要用 JS 去控制
终于有一天我认为只用 css 没准也能实现,百度了一下,结果就来了~

/* 当 dl 的同级别元素数量为 2 或者 3 时,样式生效 */
dl:nth-last-child(2):first-child,
dl:nth-last-child(2):first-child ~ dl,
dl:nth-last-child(3):first-child,
dl:nth-last-child(3):first-child ~ dl {
  width: 50%;
}