Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改css的属性_Css - Fatal编程技术网

更改css的属性

更改css的属性,css,Css,css中的新手问题: 我定义了以下样式: TABLE.tabulardata th { font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; background: #CAE8EA url(images/bg_header.jpg) no-repeat; } 我想创造一个相同的风格,但不同的背景色 问题:是否可以参数化属性。在这种情况下是背景色,还是需要像这样再次复制相同的样式 .mycla

css中的新手问题:

我定义了以下样式:

TABLE.tabulardata th {
    font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    background: #CAE8EA url(images/bg_header.jpg) no-repeat;
}
我想创造一个相同的风格,但不同的背景色

问题:是否可以参数化属性。在这种情况下是背景色,还是需要像这样再次复制相同的样式

.myclass {
    font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    background: url(images/bg_header.jpg) no-repeat;
}


TABLE.tabulardata th {
    background-color: #CAE8EA;
}

然后只需将myclass添加到您想要共享属性的任何元素。

背景色:红色

这在纯css中是不可能的。您可以使用类创建3个样式,一个是公共的,两个都是,然后将它们指定给元素

.font { font-family: Linux Biolinum; }
.red { color:red; }
.blue { color:blue; }

<div class="font red">red</div>
<span class="font blue">blue</span>
一种方法是:

TABLE.tabulardata th, TABLE.tabulardataOther th {
    font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    background: #CAE8EA url(images/bg_header.jpg) no-repeat;
}

TABLE.tabulardataOther th {
    background: #FFF url(images/other_header.jpg) no-repeat;
}

这是因为CSS的优先级。第一行将tablerdata和tablerdataother设置为相同的样式。然后第二行只覆盖tablerDataother的背景,其他属性保持不变。

这个问题不是关于设置背景颜色,他已经做了,在问题的示例中,是关于元素之间有相似的样式,但有一些不同。看看Jeriko的答案。如果你喜欢这种类型的东西,你可能想看看LESS之类的东西——你可以声明变量来保存样式,并随时调用它们,以重用/混合一组样式到新的样式中:感谢Jeriko的快速回答。这对我有帮助,我也将研究更少的选择:更少和HAML对我来说是伟大的发现——它们将作为开发人员最无聊的部分变成了一件轻而易举的事。很乐意帮忙!