如何更改Bootstrap中手风琴选项卡的背景颜色?

时间:2016-08-08 21:43:59

标签: html css twitter-bootstrap

enter image description here

我正在尝试更改手风琴上标签的背景颜色。当我在CSS中更改背景颜色时,它只会改变文本背后的颜色而不是整个颜色。

以下是我的代码的一部分:

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

4 个答案:

答案 0 :(得分:5)

如果只有文字的背景发生变化,您可能正在更改锚标记的background-color,而是使用以下CSS选择器来更改background-color panel-heading }:

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

答案 1 :(得分:0)

您可能需要为面板创建自己的自定义上下文状态类。 Bootstrap comes with a bunch built in,但如果你想要完全不同的东西,你需要添加一个。例如,这将为名为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

答案 2 :(得分:0)

Bootstrap有内置样式:

变化 <div class="panel panel-default">

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

所有其他Bootstrap颜色均适用,因此panel-success panel-warning等 见这里:Bootstrap Contextual colors

任何其他颜色都需要你编写一个类来补充引导类,例如

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

答案 3 :(得分:0)

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>