【问题标题】:Change carousel width更改轮播宽度
【发布时间】:2019-02-27 09:15:15
【问题描述】:

我有一个显示不同类型图像的轮播。它们有不同的宽度和高度。 我正在使用引导轮播。

高度没有问题,当图像显示变化时它会改变。但是对于宽度,它总是相同的(比所有图像都大,正如您在屏幕截图中看到的那样):

我的轮播代码是下一个:

<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>

关于我必须做什么才能使宽度根据图像而变化的任何想法?为什么它改变了高度而不改变宽度?

非常感谢!

【问题讨论】:

  • 你能提供轮播的css吗?
  • 我正在使用引导程序
  • 尝试用你自己的 CSS 解决它。如果遇到问题,请在此处提问,但请先自己尝试
  • 我问是因为我以前尝试过,但我没有任何好的结果,我发布了我最好的尝试......
  • 您实际使用的是哪个版本的 Bootstrap?

标签: html css twitter-bootstrap sharepoint carousel


【解决方案1】:

我把它添加到我的 css 上修复它:

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

【讨论】:

    【解决方案2】:

    根据图像高度更改轮播高度是更常见的场景,而更改轮播宽度则是更具体的场景。我认为这就是为什么默认情况下它是这样实现的。通常最好的方法是让您的图像具有相同的大小,因此在这种情况下您不必关心更改轮播大小。

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

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

    查看example

    【讨论】:

    • 我尝试像你一样,但它不起作用,它仍然一样
    【解决方案3】:

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

    class="carousel slide w-75"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-19
      • 2013-10-29
      • 2023-03-11
      • 2017-09-22
      • 2022-07-22
      • 1970-01-01
      • 2019-01-01
      • 1970-01-01
      相关资源
      最近更新 更多