Javascript CSS按钮元素类“;“继承”;

Javascript CSS按钮元素类“;“继承”;,javascript,css,html,Javascript,Css,Html,我对这一点还不熟悉,但是关于这个话题的其他问答似乎都没有帮助我,所以我会问 下面是一些代码: <style> button.accordion { background-color: #eee //a list of other details } other stuff that manipulates button.accordion </style> 手风琴{ 背景色:#eee //其他细节的清单 } 其他操纵按钮的东西。手风琴 现在,我想做这样的事情: &

我对这一点还不熟悉,但是关于这个话题的其他问答似乎都没有帮助我,所以我会问

下面是一些代码:

<style>
button.accordion {
background-color: #eee
//a list of other details
}

other stuff that manipulates button.accordion
</style>

手风琴{
背景色:#eee
//其他细节的清单
}
其他操纵按钮的东西。手风琴
现在,我想做这样的事情:

<button class="accordion">Personnel</button>
<div class="panel">
<p>contents of personnel here</p>
</div>

<button class="accordion">Necessary Expenditures</button>
<div class="panel">
<p>contents of expenditures here</p>
</div>

<button class="accordion">Personnel</button>
<div class="panel">
<p>contents of personnel here</p>
</div>

<button class="accordion">Necessary Expenditures</button>
<div class="panel">
 <p>contents of expenditures here</p>
</div>
人员
这里的人员内容

必要支出 此处的支出内容

全体人员 这里的人员内容

必要支出 此处的支出内容

我希望它们都是class=“accordion”,这样它们的功能相同,但我希望覆盖背景色,这样它们中的两个就有了不同的颜色

我尝试过添加这样一个类:

<style>
.green {
background-color: #669900;
}
</style>

格林先生{
背景色:#669900;
}
然后:

<button class="accordion green">Personnel</button>
<div class="panel">
<p>contents of personnel here</p>
</div>

<button class="accordion">Necessary Expenditures</button>
<div class="panel">
 <p>contents of expenditures here</p>
</div>
人员
这里的人员内容

必要支出 此处的支出内容

但这似乎不起作用

反正我能做到


我正在使用javascript,这样按钮就可以作为我页面的可折叠部分。

使用选择器
button.accordion
button.green
。css上的注释是
/**/
,而不是
/
<代码>#66900不是有效的十六进制颜色。在
按钮处包含缺少的
9
。绿色
背景色

button.accordion{
背景色:#eee;
/*css注释*/
/*其他细节的清单*/
}
按钮,绿色{
背景色:#669900;
}
人员
这里的人员内容

必要支出 此处的支出内容

全体人员 这里的人员内容

必要支出 此处的支出内容


按钮。手风琴
是一种比手风琴或绿色更为特殊的风格,这就是为什么它被优先考虑的原因。而不是将样式应用于
按钮。accordion
将样式应用于
.accordion
,并对单个样式(如
按钮.green
)更具体

.accordion {
  background-color: #eee;
}
button.green {
  background-color: green;
}
或者,您可以简单地将ID用于特定按钮。


手风琴{
/*背景色:#eee*/
}
格林先生{
背景颜色:绿色;
}
瑞德先生{
背景色:红色;
}
蓝先生{
背景颜色:蓝色;
}
.违约{
背景色:#EEE;
}
全体人员
这里的人员内容

必要支出 此处的支出内容

全体人员 这里的人员内容

必要支出 此处的支出内容


原因是您正在使用顶部的
按钮和
手风琴,因此它有很多特殊性。而你想要变成绿色的那个只有
.green
。这一个没有那么具体,因此它被你更具体的默认设置所掩盖。您可以组合类,以便绿色类具有更高级别的特异性。像这样:
button.accordion.green{}
然后当我调用它时,我如何像你一样完成它:
personal
这似乎不起作用它起作用了,很抱歉,我在我的十六进制中的某个点掉了一个9,然后在执行
时如何调用该类也是无效的十六进制颜色。对不起,是的,我错过了一个9。你说的“调用类”是什么意思?在
javascript