我可以用一个类名指定多个CSS类吗? [英] Can I specify multiple CSS classes with one class name?
本文介绍了我可以用一个类名指定多个CSS类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个要在元素上指定的CSS类.但是我不想每次都重复3、4或更多的课.
I have several css classes I'd like to specify on an element. But I don't want to have to repeated place 3, 4 or more classes each time.
我想去
<span class ="class1 backgroundclass borderclass iconclass">Link</span>
收件人
<span class="linkClass">Link</span>
可以做到吗?如果可以,怎么办?
Can this be done? If so, how?
推荐答案
在常规CSS中,必须将 .linkClass
包含在每个类定义中,如下所示:
In normal CSS, you would have to include .linkClass
into every class definition like this:
.class1, .linkClass { ...... }
.backgroundclass, .linkClass { ...... }
.borderclass, .linkClass { ...... }
可读性不是很好.
您可以研究CSS预处理器,例如 LessCSS ,它们可以使此操作更加容易.使用LessCSS,似乎可以执行以下操作:
You could look into CSS pre-processors like LessCSS that make this easier. With LessCSS, it seems to be possible to do the following:
.linkClass {
.class1;
.backgroundclass;
.borderclass;
}
然后,LessCSS将从中编译出最终的样式表.
LessCSS will then compile the final style sheet out of this.
这篇关于我可以用一个类名指定多个CSS类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文