H1:不(少)
您的选择器h1:not(small)不起作用,因为它说明了这一点:
Target all h1 elements that are not small elements.
它与单独使用h1选择器相同.
h1:不是(小)
你会更接近h1:not(small),它说:
Target all descendants of an h1 except small elements.
繁荣!正是你想要的.
h1 :not(small) {
color: orange;
}
This text is contained directly inside the container. It is not selectable by CSS. It is an anonymous element. This text is inside a small element
This text is contained in a span. It is selectable by CSS This text is inside a small element
CSS父选择器
对于要排除的小元素,它必须将自己标识为h1的子元素.
解决方案:两个选择器
你需要两个选择器来完成这项工作:
>第一个设置父级的样式.
>第二个覆盖孩子的第一个.
h1 {
color: orange;
}
h1 > small {
color: black;
}
I want to select this text with a css selector but not this text
更多信息