我正在编写 Bootstrap 网站上的轮播示例代码。我想为轮播中的每个项目设置不同的背景颜色。我为设置背景颜色的每个项目使用额外的 css 类。但是,我可以让它工作的唯一方法是设置重要的标志。
有什么更好的方法来处理这个问题,尤其是没有重要标志的情况下?
这是html:
<div id="myCarousel" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1" class="active"></li>
<li data-target="#myCarousel" data-slide-to="2" class="active"></li>
</ol>
<div class="carousel-inner">
<div class="item active">
<div class="container">
<div class="carousel-caption">
<h1>Example headline.</h1>
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
<p><a class="btn btn-large btn-primary" href="#">Sign up today</a></p>
</div>
</div>
</div>
<div class="item second">
<div class="container">
<div class="carousel-caption">
<h1>Second headline.</h1>
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
<p><a class="btn btn-large btn-primary" href="#">Sign up tomorrow</a></p>
</div>
</div>
</div>
<div class="item third">
<div class="container">
<div class="carousel-caption">
<h1>Third headline.</h1>
<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
<p><a class="btn btn-large btn-primary" href="#">Never sign up</a></p>
</div>
</div>
</div>
</div>
</div>
这是CSS:
.carousel .item {
height: 500px;
background-color: #777;
}
.second{
background-color: #f00 !important;
}
.third {
background-color: #0f0 !important;
}