CSS *:not(div p)不选择任何东西 [英] CSS *:not(div p) does not select anything
问题描述
我有以下HTML代码:
< div&
" p> linux版本< / p>
< h1>新工具< / h1>
有些CSS应该选择< h1>
但不选择任何内容。
*:not(div p){
font-family:sans-serif;
}
以下不起作用:
*:not(div> p){}
我有这么多
< div>
< p>
在HTML中,而以下选择并应用字体:div p {
font-family:sans-serif;
}
解决方案注释:非选择器的用法如下:
E:not(s) - 不匹配的E元素简单选择器s
其中
一个简单的选择器是一个类型选择器,通用选择器,
属性选择器,类选择器,ID选择器或伪类。
所以如果你想让代码工作,你必须添加一个类到<$ c
<$ c $ <$ p> c> *:not(.classname){
font-family:sans-serif;
}
需要向所有元素应用字体 - 通常通过在body元素中设置字体,然后文档中的其他元素将继承该规则。
可以在div中以不同的方式设置
< p& body
{
font-family:sans-serif;
}
div p
{
/ * div中需要的特殊字体族* /
}
I have the following a HTML code:
<div> <p> linux version</p> <h1> new tool </h1>
And some CSS for it that should select
<h1>
but does not select anything.*:not(div p) { font-family: sans-serif; }
The following does not work too:
*:not(div>p) {}
I have so many such
<div>
<p>
in the HTML whereas the following selects and apply the font:div p { font-family: sans-serif; }
解决方案As others have stated in the comments: the usage of the not selector is like this:
E:not(s) - an E element that does not match simple selector s
where
A simple selector is either a type selector, universal selector, attribute selector, class selector, ID selector, or pseudo-class.
So if you want you code to work you'll have to add a class to the
<p>
elements which you don't want styled with that font-family.*:not(.classname) { font-family: sans-serif; }
Alternatively: If you need to apply a font to all your elements - it is generally done by setting it in the body element, then the other elements in the document inherit that rule.
Then you can style your
<p>
elements within the div differently.body { font-family: sans-serif; } div p { /* the special font-family that you need for paragraphs within a div */ }
这篇关于CSS *:not(div p)不选择任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!