继承CSS类 [英] Inherit CSS class

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

问题描述

我有一个基础.base {}在我的CSS文件中的夫妇属性。我想只改变颜色和其他属性保持不变。如何继承这个基类的其他类?

I have one base .base{} in my CSS file with couple properties. I want to change only color and other properties to stay same. How to inherit this base class inother classes ?

推荐答案

CSS类不是OOP类。

DOM元素可以有许多类,直接或继承或其他关联,它们都将按顺序应用,覆盖早期定义的属性:

CSS "classes" are not OOP "classes". The inheritance works the other way around.
A DOM element can have many classes, either directly or inherited or otherwise associated, which will all be applied in order, overriding earlier defined properties:

<div class="foo bar">

.foo {
    color: blue;
    width: 200px;
}

.bar {
    color: red;
}

div将为200像素宽,颜色为红色。

The div will be 200px wide and have the color red.

您使用不同的类覆盖DOM元素的属性,而不是CSS类的属性。 CSSclasses是规则集,同样的方法可以使用id或标签作为规则集。

You override properties of DOM elements with different classes, not properties of CSS classes. CSS "classes" are rulesets, the same way ids or tags can be used as rulesets.

请注意,应用取决于选择器的优先级和特异性,它本身就是一个复杂的主题

Note that the order in which the classes are applied depends on the precedence and specificity of the selector, which is a complex enough topic in itself.

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

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