一个CSS类可以继承一个或多个其他类吗? [英] Can a CSS class inherit one or more other classes?

查看:139
本文介绍了一个CSS类可以继承一个或多个其他类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感到蠢的一直是一个网络程序员这么久,不知道这个问题的答案,我实际上希望它的可能,我只是不知道,而不是我认为是答案(这是不可能)。

I feel dumb for having been a web programmer for so long and not knowing the answer to this question, I actually hope it's possible and I just didn't know about rather than what I think is the answer (which is that it's not possible).

我的问题是,是否可以使一个CSS类继承另一个CSS类(或多个)。

My question is whether it is possible to make a CSS class that "inherits" from another CSS class (or more than one).

例如,假设我们有:

.something { display:inline }
.else      { background:red }

喜欢做的是这样的:

.composite 
{
   .something;
   .else
}

inline且有红色背景

where the ".composite" class would both display inline and have a red background

推荐答案

有一些工具,例如 LESS ,它们允许您以更高的抽象级别组成CSS,类似于您的描述。

There are tools like LESS, which allow you to compose CSS at a higher level of abstraction similar to what you describe.

Less调用这些Mixins

Less calls these "Mixins"

而不是

/* CSS */



#header {
  -moz-border-radius: 8px;
  -webkit-border-radius: 8px;
  border-radius: 8px;
}

#footer {
  -moz-border-radius: 8px;
  -webkit-border-radius: 8px;
  border-radius: 8px;
}

您可以说

/* LESS */



.rounded_corners {
  -moz-border-radius: 8px;
  -webkit-border-radius: 8px;
  border-radius: 8px;
}

#header {
  .rounded_corners;
}

#footer {
  .rounded_corners;
}

这篇关于一个CSS类可以继承一个或多个其他类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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