【问题标题】:Why does the size of background image change upon carousel being toggled?为什么切换轮播后背景图像的大小会发生变化?
【发布时间】:2019-06-23 02:37:13
【问题描述】:

我想知道为什么background-image 在从url/path 变为url/path2 时会垂直变大。我希望它在切换所有图像时保持不变。

我做错了什么,我该如何解决?

片段

$('.carousel').carousel({
  interval: 2000
})
.topSection {
    padding-top: 20px;
    background-image: url("https://i.stack.imgur.com/owXXD.jpg");
    max-width: 100%;
    max-height: 100%;
    position: fixed;
}

img {
    vertical-align: middle;
    border-style: none;
    width: 17em;
    margin: 5em;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

<div class="container topSection">
    <div id="carouselExampleSlidesOnly" class="carousel slide row" data-ride="carousel">
        <div class="carousel-inner">
            <div class="carousel-item active col-6">
                <img class="d-block w-10" src="https://i.stack.imgur.com/j0J5g.png" alt="First slide">
            </div>
            <div class="carousel-item">
                <img class="d-block w-10" src="https://i.stack.imgur.com/1pzi6.jpg" alt="Second slide">
            </div>
            <div class="carousel-item">
                <img class="d-block w-10" src="https://i.stack.imgur.com/1pzi6.jpg" alt="Third slide">
            </div>
        </div>
    </div>
</div>
    
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

【问题讨论】:

  • 先提供图片或任何对我们有帮助的笔
  • @NishargShah 图片已提供
  • 你的第一个图像高度较小,所以它会产生这样的效果
  • @NishargShah 是的,我想知道如何解决这个问题,这样无论身高如何,它都可以保持不变。

标签: html css debugging bootstrap-4


【解决方案1】:

由于 .topSession 的高度是 max-height: 100% ,它会根据图像的大小调整大小,所以你要做的就是定义你的类的高度,例如:

.topSection {
 padding-top: 20px;
 background-image: url("https://d2d00szk9na1qq.cloudfront.net/Product/40a055c9-72b6-4e07-aaa8-0eaf956f297c/Images/Large_0348615.jpg");
 width: 100%;
 height: 60%;
 position: fixed;
}

【讨论】:

  • 你的父母身高没有被切换,但你的孩子(img)身高一直切换到现在,你的答案在我这边不正确
猜你喜欢
  • 2019-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-21
  • 2021-02-13
  • 2018-05-01
  • 2013-07-08
  • 1970-01-01
相关资源
最近更新 更多