我有一个简单的bootstrap 4轮播,我希望轮播标题出现在顶部而不是下面的底部。
更新:此处是带有完整代码的JSFIDLE
这是我到目前为止尝试过的
HTML
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<div class="pull-left">My Gallery Title</div>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="demo" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
<div class="carousel-caption">
<h3>Heading 1</h3>
</div>
<img src="https://placeimg.com/600/400/nature/1" alt="Los Angeles">
</div>
<div class="carousel-item">
<div class="carousel-caption">
<h3>Heading 2</h3>
</div>
<img src="https://placeimg.com/600/400/nature/2" alt="Chicago">
</div>
<div class="carousel-item">
<div class="carousel-caption">
<h3>Heading 3</h3>
</div>
<img src="https://placeimg.com/600/400/nature/3" alt="New York">
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</div>
<div class="modal-footer">
<button class="btn-sm close" type="button" data-dismiss="modal">Close</button>
<!--end modal-footer-->
</div>
<!--end modal-content-->
</div>
<!--end modal-dialoge-->
</div>
<!--end myModal-->>
</div>
CSS
.carousel-caption {
position: absolute;
right: 15%;
top: -42px;
left: 15%;
z-index: 999999999;
padding-top: 20px;
padding-bottom: 20px;
color: #fff;
text-align: center;
}
不幸的是,有了这种解决方案,我的轮播字幕消失了。
我需要做什么才能得到我想要的东西?
答案 0 :(得分:1)
将top的值更改为0。轮播标题将移动到轮播顶部,与轮播指示器完全相反。 尝试使用检查元素并检查关注元素的位置。
答案 1 :(得分:1)
更改css
中的.carousel-caption
.carousel-item .carousel-caption {
position: static;
padding-top: 20px;
padding-bottom: 20px;
text-align: center;
}
工作小提琴here
答案 2 :(得分:0)
在div中使用与类“ .carousel-item”相对的属性
.carousel-item{
position:relative;
}
.carousel-caption {
position: absolute;
top: 0;
left: 0;
width:100%;
text-align:center;
z-index: 999999999;
padding-top: 5px;
color: #fff;
}
codepen中的完整工作示例: https://codepen.io/anon/pen/bJygvj