[英]how to except all elements css inside div with class?
I have html for. 我有HTML。 ex. 恩。 like this: 像这样:
<form class="smart-form">
<div>
<p></p>
<i></i>
<div>
<span class="classname"><b>text</b></span>
</div>
</div>
</form>
And there is css code for all form elements, but I need except this rules to all elements which are inside .classname: 并且所有表单元素都有css代码,但是除了这条规则,我需要对.classname中的所有元素使用此规则:
.smart-form *,
.smart-form *:after,
.smart-form *:before {
margin: 0;
padding: 0;
box-sizing: content-box;
-moz-box-sizing: content-box;
}
I tried like this: 我这样尝试过:
.smart-form *:not(> .classname *) {} // but its wrong
From this SO answer by @BoltClock♦: 从@ BoltClock♦得到的答案中 :
:not()
only accepts one simple selector at a time;:not()
只接受一个简单的选择器; this is mentioned in the Selectors 3 spec: 在Selectors 3规范中提到了这一点:
… ...
If you want to use this negation by itself, selecting all other elements, then there isn't a way using just a selector. 如果您想单独使用这种否定,选择所有其他元素,那么就没有办法只使用选择器。
In other words, there is no way to nest a descendant selector inside a :not()
selector. 换句话说,没有办法将后代选择器嵌套在:not()
选择器中。
As an alternative, I'm suggesting a bit of a paradigm shift in your approach: instead of selecting all the elements except the ones inside the class .classname
, add all the rules you want for the other elements and then reverse them by adjusting the .classname
styles. 作为替代方案,我建议您在方法上进行一些范式转换:不要选择除 .classname
类中的所有元素以外的所有元素,而是为其他元素添加所需的所有规则,然后通过调整.classname
样式。 Ie,: IE中:
.smart-form * {
/* general CSS styles for .smart-form children */
}
.smart-form .classname, form .classname * {
/* specific CSS styles for .classname children */
}
This should select all the descendants that are of class .classname
. 这应该选择所有.classname
类的后代。
.smart-form *, .smart-form *:after, .smart-form *:before { margin: 0; padding: 0; box-sizing: content-box; -moz-box-sizing: content-box; } /* you can use initial or auto in most cases to set the properties back to default */ .smart-form .classname, .smart-form .classname * { margin: initial; padding: initial; box-sizing: initial; -moz-box-sizing: initial; }
<form class="smart-form"> <div> <p></p> <i></i> <div> <span class="classname"><b>text</b></span> </div> </div> </form>
In the example above, the styles are set to all the elements, but then they are reversed by the ones just for .classname
. 在上面的示例中,样式设置为所有元素,但随后仅用于.classname
的样式被颠倒。
I think you should not put css on it and just put css on where you want inside your div. 我认为您不应该将CSS放在上面,而应该将CSS放在div中您想要的位置。 What is the point of putting css if you just want to have exception? 如果您只想拥有异常,放置css有什么意义?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.