简体   繁体   English

twitter bootstrap轮播字幕不匹配照片宽度

[英]twitter bootstrap carousel caption not matching photo width

I have the Twitter Bootstrap carousel working quite well for the most part but my photos are of different widths and the caption on the bottom matches the widest width so when I have photos with less width the caption stays black for the previous width and looks a little unprofessional. 我的Twitter Bootstrap轮播在大多数情况下都能很好地工作,但是我的照片的宽度不同,底部的标题与最宽的宽度匹配,所以当我的照片宽度较小时,标题在以前的宽度上保持黑色,看上去有点不专业。 My code is as follows and I was wondering if there is any way to fix this problem so the width always matches the photo. 我的代码如下,我想知道是否有任何方法可以解决此问题,因此宽度始终与照片匹配。

<div class="row">
    <div class="span8 offset2">
            <div id="myCarousel" class="carousel slide">

                  <div class="carousel-inner">

                 <!-- here I loop through and add a bunch of photos -->
                  {% for photo in record_photos %}

                    <div class="active item">
                        <a href="/url"><img src="some-src"></a>
                        <div class="carousel-caption">
                            <h3 class="center-it">some caption</h3>
                        </div>
                    </div>

                   {% endfor %}

                  </div>

                  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
                  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>

            </div>
        </div>
    </div>

I suggest picking a span size that will be the optimum size for the photo widths that you have as span will determine the carousel width. 我建议选择一个跨度大小,该大小将是您拥有的照片宽度的最佳大小,因为跨度将决定转盘的宽度。 Larger images will shrink to the span width. 较大的图像将缩小到跨度宽度。 Smaller images you could 'upsize' by placing them in a larger image with a solid (or transparent) background. 通过将较小的图像放置在具有纯色(或透明)背景的较大图像中,可以“放大”图像。

Carousel is designed to show images in the span it is in - conceivably you could dynamically alter the width but personally I think the changes would be somewhat visually jarring between images and there would be the back/next button locations to deal with as well. Carousel旨在显示其跨度内的图像-可以动态地更改宽度,但是我个人认为这些更改在图像之间在视觉上会产生震撼,并且还会有后退/下一个按钮位置需要处理。

BTW, note that in your template code above, every item is active. 顺便说一句,请注意,在上面的模板代码中,每个项目都是活动的。 You will need to put some logic into the loop so that only the first loop iteration produces an item with active class 您将需要在循环中添加一些逻辑,以便只有第一个循环迭代才能生成具有活动类的项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM