Html 添加多个类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3935632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding more than one class
提问by good_evening
Is it bad thing if I add more than one class for one object. Let's say:
如果我为一个对象添加多个类是不是坏事。让我们说:
<a href="#" class="paren" class="defaul">text</a>
<a href="#" class="paren" class="defaul">text</a>
Don't ask me why, I just need it.
不要问我为什么,我只是需要它。
Thanks.
谢谢。
回答by RedFilter
You can use multiple class names (a perfectly normal thing to do), but are only allowed one class attribute on your HTML element.
您可以使用多个类名(这是一件非常正常的事情),但只允许在您的 HTML 元素上使用一个类属性。
Do this instead:
改为这样做:
<a href="#" class="paren defaul">text</a>
回答by Kieran Ryan
Following on from RedFilters' answer you could of course extend your class selectors by using the angularng-class attribute as follows:
继 RedFilters 的回答之后,您当然可以通过使用angularng-class 属性来扩展您的类选择器,如下所示:
<a href="#" class="paren defaul" ng-class="['tea', 'mat', 'thirs']">text</a>
The resulting html would then be:
生成的 html 将是:
<a href="#" class="paren defaul tea mat thirs">text</a>
Might come in useful to get around a tslint "line too long" error :-)
可能有助于解决 tslint“行太长”错误:-)
回答by Alejandro del Río
There's no need for two class statements, simply:
不需要两个 class 语句,只需:
<a href="#" class="paren defaul">text</a>
Now, in order to handle this in CSS you need to do this:
现在,为了在 CSS 中处理此问题,您需要执行以下操作:
.paren.default{
}
...Whithout spaces between the two class selectors. Cheers!
...两个类选择器之间没有空格。干杯!