简体   繁体   中英

How do I change the background-color of an accordion tab in Bootstrap?

在此处输入图片说明

I am trying to change the background color of the tabs on my accordion. When I change the background color in CSS, it just changes the color behind the text and not the entire thing.

Here is a segment of my code:

<div class="panel-group" id="accordion">
    <div class="panel panel-default">
        <div class="panel-heading">
        <h4 class="panel-title">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
      Collapsible Group Item #1
            </a>
        </h4>
        </div>
        <div id="collapseOne" class="panel-collapse collapse in">
        <div class="panel-body">
            Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
    </div>
    </div>
</div>

You are probably changing the background-color of the anchor tag if only the text's background is changing, instead, use the following CSS selector to change the background-color of the panel-heading :

.panel-default > .panel-heading {
    background-color:#000;
}

You likely need to create your own custom contextual state class for the panel. Bootstrap comes with a bunch built in , but if you want something completely different you'll need to add one. This for example would create a new contextual state class for the panels called flashy:

.panel-flashy {
    border-color: #FF934F;
  }
.panel-flashy > .panel-heading {
     color:#fff;
     background-color:#FF934F;
     border-color:#ff934f;
}

HTML code:

     <div class="panel panel-flashy">
        <div class="panel-heading">
           <h3 class="panel-title">Flashy Panel title</h3>
        </div>
        <div class="panel-body">
           Panel content goes here
        </div>
     </div>

Bootply example .

Bootstrap has built-in styles:

change <div class="panel panel-default">

to <div class="panel panel-primary">

all the other Bootstrap colours apply, so panel-success panel-warning etc see here: Bootstrap Contextual colors

any other colour would require you to write a class to supplement the bootstrap classes eg

.panel-turquoise {
    border-color: #32c5d2;
}
.panel-turquoise > .panel-heading + .panel-collapse > .panel-body {
    border-top-color: #32c5d2;
}

.panel-turquoise > .panel-heading {
    background-color: #eff3ff;
}

<div class="panel panel-turquoise">

bg-default

<div class="panel-group" id="accordion">
<div class="panel bg-default">
    <div class="panel-heading">
    <h4 class="panel-title">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
  Collapsible Group Item #1
        </a>
    </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in">
    <div class="panel-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM