Конечно, объедините :first-child
и :last-child
в один селектор:
.node-child:first-child:last-child {
/* Styles for when it is one element with no siblings */
}
Или наоборот:
.node-child:first-child:not(:last-child),
.node-child:last-child:not(:first-child),
.node-child:not(:first-child):not(:lsat-child), {
/* Styles for when there are more than one, i.e. ther are siblings */
}
Чтобы быть еще более лаконичным для вашего конкретный c случай, используйте :only-child
, где эквиваленты были бы:
.node-child:only-child {
/* Styles for when it is one element with no siblings */
}
И эквивалентный противоположный, даже более чистый:
.node-child:not(:only-child) {
/* Styles for when it is one element with no siblings */
}
Это совершенно безопасно для использования only-child
при условии, что вы, конечно, не поддерживает IE8!