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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38838980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 00:12:07  来源:igfitidea点击:

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

htmlcsstwitter-bootstrap

提问by Kory Hershock

enter image description here

在此处输入图片说明

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>

回答by APAD1

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

background-color如果仅更改文本的背景,您可能正在更改锚标记的 ,而是使用以下 CSS 选择器更改background-colorpanel-heading

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

回答by Mary Wheeler

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:

您可能需要为面板创建自己的自定义上下文状态类。Bootstrap 内置了一堆,但是如果您想要完全不同的东西,则需要添加一个。例如,这将为名为 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 示例

回答by Adam Hey

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-successpanel-warningetc see here: Bootstrap Contextual colors

所有其他 Bootstrap 颜色都适用,因此panel-successpanel-warning请参见此处:Bootstrap Contextual colours

any other colour would require you to write a class to supplement the bootstrap classes e.g.

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

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

<div class="panel panel-turquoise">

回答by ???? ????? ???? ??????

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>