是否可以从另一个 CSS 类(或多个)“继承”一个 CSS 类。
例如,假设我们有:
.something { display:inline }
.else { background:red }
我想做的是这样的:
.composite
{
.something;
.else
}
其中“.composite”类将同时显示内联并具有红色背景

有像LESS这样的工具,它允许您在更高的抽象级别上编写 CSS,类似于您所描述的。
较少的调用这些“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;
}
您可以向单个 DOM 元素添加多个类,例如
<div cl="firstCl secondCl thirdcl fourthcl"></div>
在后面的类中给出的规则(或更具体)覆盖。因此,该示例中的fourthcl
占上风。
继承不是 CSS 标准的一部分。

是的,但不完全是这种语法。
.composite,
.something { display:inline }
.composite,
.else { background:red }

将您的通用属性放在一起,并再次分配特定(或覆盖)属性。
/* ------------------------------------------------------------------------------ */
/* Headings */
/* ------------------------------------------------------------------------------ */
h1, h2, h3, h4
{
font-family : myfind-bold;
color : #4C4C4C;
display:inline-block;
width:900px;
text-align:left;
background-image: linear-gradient(0, #F4F4F4, #FEFEFE);/* IE6 & IE7 */
}
h1
{
font-size : 300%;
padding : 45px 40px 45px 0px;
}
h2
{
font-size : 200%;
padding : 30px 25px 30px 0px;
}
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(60条)