我正试图将一个按钮放在一个bootstrap 3旋转木马上,这个按钮悬停在旋转木马上方。
我尝试将按钮包装在div类中,并使用text-align:center;或保证金:0自动;没有成功。
我可以手动设置.hover-class的margin-left;这会起作用,但它并不完全集中。如何居中我的按钮?
这是我的代码:
HTML:
<!--The slider-->
<section>
<div class="hover-slide">
<a href="#page-intro" class="btn btn-default start-me">Let's go</a>
</div>
<div id="slider-top" class="carousel slide" data-ride="carousel">
<!--Indicators-->
<ol class="carousel-indicators">
<li data-target="#slider-top" data-slide-to="0" class="active"></li>
<li data-target="#slider-top" data-slide-to="1"></li>
<!--<li data-target="#slider-top" data-slide-to="2"></li>-->
</ol>
<!--Wrapper for the the slide-->
<div class="carousel-inner">
<!--specify first slide-->
<div class="item active">
<img src="img/01.jpg" alt="Foto1">
<div class="carousel-caption">
<h3>TEST</h3>
</div>
</div>
<!--specify second slide-->
<div class="item">
<img src="img/02.jpg" alt="Foto2">
<div class="carousel-caption">
<!--<a href="#page-intro" class="btn btn-default start-me">Let's go</a>-->
<h3>TEST SLIDE 2</h3>
</div>
</div>
</div>
<a class="carousel-control left" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
我的CSS:
.hover-slide {
position: absolute;
/*margin-left: 30%;*/
z-index: 10;
}
.carousel .item {
width: 100%;
height: 100%;
}
.carousel .item img {
width: 100%;
height: 100%;
}
.btn.start-me {margin: 0 auto;}
答案 0 :(得分:6)
您需要换行并添加text-center
类:
提取:
<section>
<div class="col-md-12 hover-slide text-center"> // <------ HERE
<a href="#page-intro" class="btn btn-default start-me">Let's go</a>
</div>
<div id="slider-top" class="carousel slide col-md-12" data-ride="carousel"> // <------ HERE
<ol class="carousel-indicators">
<li data-target="#slider-top" data-slide-to="0" class="active"></li>
<li data-target="#slider-top" data-slide-to="1"></li>
<!--<li data-target="#slider-top" data-slide-to="2"></li>-->
</ol>