我们可以在另一个css类中包含公共css类吗? [英] Can we include common css class in another css class?

查看:458
本文介绍了我们可以在另一个css类中包含公共css类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个CSS新手。我只是想知道,是否可能将一个公共类包括在另一个类中?

I am a CSS newbie. I am just wondering, is that possible to include one common class into another class?

例如,

.center {align: center};
.content { include .center here};

我遇到了css框架 - 蓝图。我们需要将位置信息放入HTML,例如

I came across css framework - Blueprint. We need to put the position information into HTML, e.g.

<div class="span-4"><div class="span-24 last">

因此,我们将在html中放置定位属性,而不是css。如果我们改变布局,我们需要改变html,而不是css。

As such, we will place the positioning attribute inside html, instead of css. If we change the layout, we need to change html, instead of css.

这是我问这个问题的原因。如果我可以包括.span-4到我自己的css,我不必在我的html标签中指定它。

That's the reason I ask this question. If I can include .span-4 into my own css, i won't have to specify it in my html tag.

推荐答案

奇怪的是,即使CSS谈论继承,类也不能以这种方式继承。你最好做的是这样:

Bizarrely, even though CSS talks about inheritance, classes can't "inherit" in this way. The best you can really do is this:

.center, .content { align: center; }
.content { /* ... */ }

建议你不要这样做裸体类选择器。尽可能使用和ID或标签和类:

Also I'd strongly suggest you not do "naked" class selectors like this. Use and ID or tag and class where possible:

div.center, div.content { align: center; }
div.content { /* ... */ }

如果你做你的选择器尽可能广泛,最终变得无法管理(在我的经验)一旦你得到大型的样式表。你最终会有非预期的选择器互相交互,创建一个新类(例如.center2),因为更改原始类会影响你不想要的所有类型。

I say this because if you do your selectors as broad as possible it ends up becoming unmanageable (in my experience) once you get large stylesheets. You end up with unintended selectors interacting with each other to the point where you create a new class (like .center2) because changing the original will affect all sorts of things you don't want.

这篇关于我们可以在另一个css类中包含公共css类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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