简体   繁体   English

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

[英]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.当我在 CSS 中更改背景颜色时,它只会更改文本背后的颜色,而不是整个内容。

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 :如果仅更改文本的背景,您可能正在更改锚标记的background-color ,而是使用以下 CSS 选择器更改panel-headingbackground-color

.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. Bootstrap 内置了一堆,但是如果您想要完全不同的东西,则需要添加一个。 This for example would create a new contextual state class for the panels called flashy:例如,这将为名为 flashy 的面板创建一个新的上下文状态类:

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

HTML code: HTML代码:

     <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 . Bootply 示例

Bootstrap has built-in styles: Bootstrap 具有内置样式:

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

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

all the other Bootstrap colours apply, so panel-success panel-warning etc see here: Bootstrap Contextual colors所有其他 Bootstrap 颜色都适用,因此panel-success panel-warning等请参见此处: Bootstrap Contextual colours

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 bg-默认

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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