I'm trying to select the first and last child of an element with a specific data-
attribute.
Bottom line is, there's no way to do that in CSS.
last-child
(and last-of-type
) mean, well, "last child", and "last child of type", they do not mean "last child matching the entire selector including an attribute selector". In your case, it is likely that the third div
is not actually the last child (or not the last div
) within the parent element; it's impossible to tell unless you show the entire HTML including the parent element and all its children.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…