Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Button Element Class "Inheritance"

I'm new to this, but none of the other q/a's on the topic seem to help me, so I will ask.

Here is some code:

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

other stuff that manipulates button.accordion
</style>

Now, I want to do something like this:

<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>

And I want them all to be class="accordion" so that they function the same way, but I want to override background-color so that a couple of them have a different color.

I have tried adding a class like so:

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

and then:

<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>

but that doesn't seem to work.

Anyway I can do this?

I am using javascript so that the buttons act as collapsible sections to my page.

like image 565
sam_sows Avatar asked Jan 28 '26 23:01

sam_sows


1 Answers

Use selectors button.accordion, button.green. Comment at css is /**/, not //. #66900 is not a valid hex color. Include missing 9 at button.green background-color value.

button.accordion {
  background-color: #eee;
  /* css comment */
  /* a list of other details */

}
button.green {
  background-color: #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>

<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>
like image 113
guest271314 Avatar answered Jan 31 '26 13:01

guest271314