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

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

问题描述

是否可以创建一个继承"CSS 类?来自另一个 CSS 类(或多个).

Is it 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
}

其中.composite"类将显示内联并具有红色背景

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.

少称这些为混音"

代替

/* 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天全站免登陆