具有不同图像大小的缩略图Bootstrap

时间:2014-04-30 03:46:18

标签: jquery html css twitter-bootstrap

我想要包含不同大小和不同文本数量的缩略图。但我希望它们都具有相同的尺寸。像这样example from the Bootstrap site

以下是我目前的代码,demo on jsFiddle

我有不同的图像大小,所以这会被打破。 Bootstrap可以实现吗?

<div class="col-sm-6 col-md-4">
    <div class="thumbnail">
        <h3>
            Fading a RGB LED on BeagleBone Black
        </h3><img src="https://learn.adafruit.com/system/guides/images/000/000/322/medium310/overview_web.jpg?" alt="Sample Image">
        <div class="caption">
            <p>In this tutorial, you will learn how to control the color of an RGB LED using a BeagleBone Black and Python.</p>
        </div>
    </div>
</div>
<div class="col-sm-6 col-md-4">
    <div class="thumbnail">
        <h3>
            Measuring Light with a BeagleBone Black
        </h3><img src="https://learn.adafruit.com/system/guides/images/000/000/316/medium310/overview_web.jpg?" alt="Sample Image">
        <div class="caption">
            <p>In this tutorial, you will learn how to connect a photoresistor to a BeagleBone Black. The tutorial can also be used for other resistive sensors such as FSRs or SoftPots.</p>
        </div>
    </div>
</div>

4 个答案:

答案 0 :(得分:22)

您可以通过定义容器的尺寸来实现这一目标。

例如在您的容器元素(.thumbnail)中,设置一个特定的尺寸,如:

.thumbnail{        
    width: 300px; 
    // or you could use percentage values for responsive layout
    // width : 100%;
    height: 500px;
    overflow: auto;
}

.thumbnail img{
    // your styles for the image
    width: 100%;
    height: auto;
    display: block;
}

以及其他元素。

<强> SAMPLE

答案 1 :(得分:4)

您可以使用img标记上的CSS来完成此操作。

img {
    width: 200px;
    height: 200px;
}

或内联每个img代码,如此

<img style="width: 200px; height: 200px" src="https://learn.adafruit.com/system/guides/images/000/000/339/medium310/overview_web.jpg" alt="Sample Image">

答案 2 :(得分:1)

您应该设置这些列的高度。例如,我们有相同数量的文本,因此每个div都有相同的高度。

答案 3 :(得分:0)

这是我的解决方案,希望有所帮助!

  <style type="text/css">
  .row{
    display: flex;
   flex-wrap: wrap;
  }
  .row>[class="col-sm-6 col-md-4"]{
    display: flex;
    flex-direction: column;
  }
</style>