首页 文章

改变轮播宽度

提问于
浏览
0

我有一个显示不同类型图像的旋转木马 . 它们具有不同的宽度和高度 . I'm using bootstrap carousel.

有了高度,没有问题,它会在图像显示变化时发生变化 . 但是对于宽度,它总是一样(比所有图像都大,如截图所示):

enter image description here

我的轮播代码是下一个:

<div class="container">
<div id="myCarousel" class="carousel slide" data-ride="carousel" margin: 0 auto">

    <!-- Wrapper for slides -->
    <div class="carousel-inner">
        <asp:Repeater ID="repeaterImages" runat="server">
            <ItemTemplate>
                <div class="carousel item <%# (Container.ItemIndex == 0 ? "active" : "") %>">
                    <asp:Image ID="Image1" ImageUrl='<%# Eval("FileName") %>' runat="server" />
                </div>
            </ItemTemplate>
        </asp:Repeater>
    </div>

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

有什么想法,我必须做的是根据图像改变宽度?为什么它会改变高度但不改变宽度?

非常感谢!

3 回答

  • 0

    我修复它在我的CSS上添加:

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

    根据图像高度改变轮播高度是更常见的情况,而改变轮播宽度是更具体的情况 . 我认为这就是默认情况下这样实现的原因 . 通常最好的方法是预先设置您的图像大小相同,因此在这种情况下,您不必关心更改轮播的大小 .

    但是,您可以使用Carousel Events更改轮播宽度:

    $('#carouselExampleControls').on('slid.bs.carousel', resizeCarousel);
    $(document).ready(resizeCarousel);
    
    function resizeCarousel(){
        var imgWidth = $('.carousel-item.active img').width();
        $('#carouselContainer').width(imgWidth);
    }
    

    example

  • 0

    Bootstrap - 内联样式 <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" style="width: 80%;">

    class="carousel slide w-75"

相关问题