在另一个选择器中导入CSS选择器样式? (NOT @import) [英] Import CSS Selector Styles in Another Selector? (NOT @import)

查看:158
本文介绍了在另一个选择器中导入CSS选择器样式? (NOT @import)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以将单个CSS选择器的样式导入到另一个CSS选择器中,并添加到其中或从其中重写属性。

Is there a way to import the styling of a single CSS selector into another CSS selector and add to it or rewrite properties from it.

p>

Let's say:

.original_class{
background:black;
color:white;
}
.overwrite{
@import(.original_class); /* I know this doesn't work */
color:blue;
border:1px solid green;
}



我可以通过重新声明.original_class并赋值CSS样式从上到下重写),但这将替换原始CSS类的属性。我想要的是继承它的属性到另一个类,而不必再次写(重复)。

I can accomplish this by just redeclaring the .original_class and assigning new values (since CSS styles are rewritten from top to bottom), but this will replace the attributes of the original CSS class. What I want is to inherit its properties into another class without having to write them again (duplicate).

推荐答案

您可以在HTML中执行类似的操作:

You could do something like this in your HTML:

<div class="original_class overwrite">...</div>

这将有相同的效果,但你必须为每个你想要的样式

This will have the same effect, but you will have to do this for every element you want styled that way.

还可以使用CSS预处理器,例如 SASS ,它支持继承/ mixins。

There is also the option of using a CSS pre-processor, like SASS, which supports inheritance/mixins.

这篇关于在另一个选择器中导入CSS选择器样式? (NOT @import)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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