首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >让Bootstrap的旋转木马既有中心又有响应性?

让Bootstrap的旋转木马既有中心又有响应性?
EN

Stack Overflow用户
提问于 2013-10-25 14:12:00
回答 13查看 149.8K关注 0票数 35

我希望我的旋转木马图像在中心(水平),这不是默认的。我遵循this topic的解决方案。

但是,使用此解决方案时,当轮播调整大小并小于图像时,图像将被裁剪,而不是按默认比例缩放。

我如何既使图像居中,又使其伸展到旋转木马项目?

EN

回答 13

Stack Overflow用户

回答已采纳

发布于 2015-02-02 01:17:18

现在(在Boostrap 3+上)很简单:

代码语言:javascript
复制
.carousel-inner img {
  margin: auto;
}
票数 76
EN

Stack Overflow用户

发布于 2013-10-25 15:12:59

我假设你有不同大小的图片。我自己测试过了,它就像你描述的那样工作(总是居中,图像宽度合适)

代码语言:javascript
复制
/*CSS*/
div.c-wrapper{
    width: 80%; /* for example */
    margin: auto;
}

.carousel-inner > .item > img, 
.carousel-inner > .item > a > img{
width: 100%; /* use this, or not */
margin: auto;
}

<!--html-->
<div class="c-wrapper">
<div id="carousel-example-generic" class="carousel slide">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
    <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    <li data-target="#carousel-example-generic" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active">
      <img src="http://placehold.it/600x400">
      <div class="carousel-caption">
        hello
      </div>
    </div>
        <div class="item">
      <img src="http://placehold.it/500x400">
      <div class="carousel-caption">
        hello
      </div>
    </div>
    <div class="item">
      <img src="http://placehold.it/700x400">
      <div class="carousel-caption">
        hello
      </div>
    </div>
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
    <span class="icon-prev"></span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
    <span class="icon-next"></span>
  </a>
</div>
</div>

这就产生了一个“跳跃”,因为可变的高度...要解决这个问题,可以尝试下面这样的代码:Select the tallest image of a list

或者使用media-query设置您自己的固定高度。

票数 33
EN

Stack Overflow用户

发布于 2017-08-29 17:13:23

在Boostrap4上,只需将mx-auto添加到您的旋转木马图像类中。

代码语言:javascript
复制
<div class="carousel-item">
  <img class="d-block mx-auto" src="http://placehold.it/600x400" />
</div> 

根据需要与bootstrap carousel documentation中的样本相结合。

票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19582340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档