是否可以在CSS中组合类? [英] Is it possible to combine classes in CSS?

查看:46
本文介绍了是否可以在CSS中组合类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个en元素< div clas ="foo bar foobar"> [stuff]</div> ,并且我想用一个类(SuperFoo)替换这三个类

Suppose I have a en element <div clas="foo bar foobar">[stuff]</div> and I want to replace these three classes with one class (SuperFoo).

虽然我可以找出foo,bar和foobar的定义方式,并使用其中的每个元素:

While I could find out how foo, bar and foobar are defined, and use each of those elements:

.SuperFoo {color:red} 等,是否可以根据foo,bar和foobar定义SuperFoo?

.SuperFoo { color : red } and so on, is it possible to define SuperFoo in terms of foo, bar and foobar?

.SuperFoo {foo bar foobar} ?

我该怎么做?

推荐答案

除非您使用其他 SASS 的'mixin'功能,纯CSS没有真正的方法来继承"其他类.

Unless you use LESS or SASS's 'mixin' features, there's no real way in plain CSS to "inherit" other classes.

您能做的最好的就是将这三个类都应用于DOM元素.

The best you can do is apply all three classes to your DOM element.

如果您的问题是页面上已经有很多此类,并且您想向所有这些类添加属性,则可以执行以下操作:

If your problem is that you have a ton of those classes already on a page and you want to add properties to all of them, you can do:

.foo, .bar, .foobar {
    color: red;
}

并且将应用颜色:红色到具有.foo或.bar或.foobar的任何元素.

and that will apply color: red to any element that has .foo or .bar or .foobar.

这篇关于是否可以在CSS中组合类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆