在没有添加任何类(或触摸HTML)的情况下,如果该div中有第二个元素,有没有办法将div中的第一个元素作为目标?以下是我的HTML:
I WANT TO APPLY CSS TO THISBut only if there is 2nd .content element in the same parent elementDon't apply hereDon't apply hereI WANT TO APPLY CSS TO THISBut only if there is 2nd .content element in the same parent element
为了获得更好的图片,可以使用一些上下文...我想把.content
它放在中心,如果它是内部唯一的.content .grid
.但如果有两个.content
div,那么我希望它们彼此相邻.
注意:
我已经知道我可以瞄准第二个.content
了
.grid .content:nth-child(2) { ... }
MortenMoulde.. 9
.grid > .content:first-child:not(:only-child) {
color: blue;
}
I WANT TO APPLY CSS TO THIS
But only if there is 2nd .content element in the same parent element
Don't apply here
Don't apply here
I WANT TO APPLY CSS TO THIS
But only if there is 2nd .content element in the same parent element
:first-child:not(:only-child)
将是你的选择器.
.grid > .content:first-child:not(:only-child) {
color: blue;
}
I WANT TO APPLY CSS TO THIS
But only if there is 2nd .content element in the same parent element
Don't apply here
Don't apply here
I WANT TO APPLY CSS TO THIS
But only if there is 2nd .content element in the same parent element