【问题标题】:bootstrap thumbnail images same size引导缩略图图像相同大小
【发布时间】:2017-03-18 01:12:55
【问题描述】:

我正在使用引导缩略图,其中每个缩略图都包含一个图像和一个标题。 问题是图像的大小不同,我希望它们以相同的大小显示,以使缩略图具有相同的尺寸。我正在使用 angular ng-repeat 来获取带有图像和名称的国家/地区列表。

<style>
  .thumbnail:hover{
    background: #f7f7f7;
  }
 .thumbnail img{
    border-radius: 100%;
    height: 98px;
    width: 137px;
    border:solid 1px #cccccc;
  }
</style>
<div class="row">
  <div ng-repeat="team in $ctrl.teams">
    <div class="col-sm-3 col-md-2">
      <div class="thumbnail">
       <a href="">
        <img ng-src="{{team.imgpath}}"  alt="team"/>
        <div class="caption text-center">
          <h4>{{team.name}}</h4>
        </div>
       </a>
      </div>
    </div>
  </div>
</div> 

我为高度和宽度设置了固定值,但是,图像不会以相同的尺寸显示,因为它们最初的尺寸不同。

如何使用引导程序保持内容响应并让图像以相同大小显示?

【问题讨论】:

  • 如果你使用 angularjs,ng-repeat 用于显示具有不同内容的相同结构,这里我得到一个国家数组,每个国家我显示它缩略图中的内容。国家的img大小不同的问题,即使我设置了固定的高度和宽度,bootstrap也不会显示它们相等。
  • 在您的示例中,您有 pic1 [height: 125, width: 125], pic2 [height: 250, width: 250],其中 width = height。我的照片没有宽度 = 高度。我有 pic1 [高度:393,宽度:550] 和 pic2 [高度:369,宽度:550]。大部分宽度相同,高度不同。
  • 我已经创建了另一个小提琴,希望这有助于jsfiddle.net/y12rgpdL
  • @Hardik 没有真正的理由添加额外的标记来解决问题,使用特异性,一切都很好。

标签: jquery html css angularjs twitter-bootstrap


【解决方案1】:

Bootstrap 使用两个类来定位缩略图:

.thumbnail img.thumbnail a &gt; img

您需要使用具有更高特异性的那个 (.thumbnail a &gt; img),这样您的样式就不会被覆盖。

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');

.thumbnail:hover {
  background: #f7f7f7;
}

.thumbnail a > img {
  border-radius: 100%;
  height: 98px;
  width: 137px;
  border: solid 1px #cccccc;
}
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3 col-md-2">
      <div class="thumbnail">
        <a href="">
          <img src="http://placehold.it/125x70" alt="team">
          <div class="caption text-center">
            <h4>{{team.name}}</h4>
          </div>
        </a>
      </div>
    </div>
    <div class="col-sm-3 col-md-2">
      <div class="thumbnail">
        <a href="">
          <img src="http://placehold.it/250x140" alt="team">
          <div class="caption text-center">
            <h4>{{team.name}}</h4>
          </div>
        </a>
      </div>
    </div>
    <div class="col-sm-3 col-md-2">
      <div class="thumbnail">
        <a href="">
          <img src="http://placehold.it/125x70" alt="team">
          <div class="caption text-center">
            <h4>{{team.name}}</h4>
          </div>
        </a>
      </div>
    </div>
    <div class="col-sm-3 col-md-2">
      <div class="thumbnail">
        <a href="">
          <img src="http://placehold.it/75x25" alt="team">
          <div class="caption text-center">
            <h4>{{team.name}}</h4>
          </div>
        </a>
      </div>
    </div>
    <div class="col-sm-3 col-md-2">
      <div class="thumbnail">
        <a href="">
          <img src="http://placehold.it/125x70" alt="team">
          <div class="caption text-center">
            <h4>{{team.name}}</h4>
          </div>
        </a>
      </div>
    </div>
    <div class="col-sm-3 col-md-2">
      <div class="thumbnail">
        <a href="">
          <img src="http://placehold.it/125x70" alt="team">
          <div class="caption text-center">
            <h4>{{team.name}}</h4>
          </div>
        </a>
      </div>
    </div>
  </div>
</div>

【讨论】:

  • 完美解决方案:)
  • 太棒了!请注意,我删除了我的 cmets,因为它们是基于我造成的错误并且不再有效。
  • 谢谢@hungerstar! :) 会注意到这一点
猜你喜欢
  • 2014-09-30
  • 1970-01-01
  • 1970-01-01
  • 2017-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-20
  • 1970-01-01
相关资源
最近更新 更多