gpt4 book ai didi

html - 将 Bootstrap 轮播居中

转载 作者:行者123 更新时间:2023-11-28 05:20:24 26 4
gpt4 key购买 nike

我在我的主页上创建了一个 Bootstrap Carousel,在一些文本信息之后。我不想在我的页面中使用大轮播,所以我使用 <div class="col-sm-6"> 减小了大小.但是我的 Carousel 位于页面的左侧,我无法将它居中。我想把它放在我页面的中央。我使用的代码是:

<div class="container">
<h4 class="text-justify">text here </h4>
</div>

<div class="container">
<div class="col-sm-6">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
</ol>

<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active"><img src="https://upload.wikimedia.org/xx.JPG" alt=""></div>
<div class="item"><img src="https://upload.wikimedia.org/wikipedia/xxxx.JPG" alt=""></div>
</div>

<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span></a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div></div></div>

我的 CSS 代码是

.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
width: 100%;
margin: auto;
}

如何改变位置?

最佳答案

首先你必须将你的 col-sm-6 放在一行中,然后你可以简单地添加一个类“col-centered”并添加以下 CSS

.col-centered{
float: none;
margin: 0 auto;
}

你的最终代码将是这样的:

<div class="container">
<h4 class="text-justify">text here </h4>
</div>

<div class="container">
<div class="row">
<div class="col-sm-6 col-centered">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
</ol>

<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active"><img src="https://upload.wikimedia.org/xx.JPG" alt=""></div>
<div class="item"><img src="https://upload.wikimedia.org/wikipedia/xxxx.JPG" alt=""></div>
</div>

<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span></a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
</div>

关于html - 将 Bootstrap 轮播居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39534878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com