dsstjqsr631426 2016-03-29 00:12
浏览 53
已采纳

尽管使用Bootstrap上传尺寸,但强制Wordpress图像具有相同的高度

I have some code to output images in Wordpress like this...

<div class="col-md-2">

<?php $image = get_field('artist_photo');
       if( !empty($image) ): 
        // thumbnail
        $size = 'medium';
        $thumb = $image['sizes'][ $size ];
       ?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" class="img-responsive" />

</div>

<?php endif; ?>

The problem is, all of the images have different heights (based on their proportions at original upload}.

Is it possible to make them have a uniform height whilst remaining responsive?

  • 写回答

1条回答 默认 最新

  • duanniying2342 2016-03-29 00:45
    关注

    Here are two ways to constrain the height of an image in CSS.

    First, you can set a maximum height. So something like:

    .col-md-2 img {
      display: block;
      max-height: 300px;
      width: auto;
      height: auto;
    }
    

    Second, you can display the image as a background image and then use the background-size property to constrain it. In your markup display the image using:

    <div class="image" style="background: url(<?php echo $thumb; ?>) no-repeat center;" />
    

    And style it like so:

    .col-md-2 {
      height: 300px;
    }
    
    .col-md-2 div.image {
      height: 100%;
      width: 25%; // for example, assuming you want 4 images per row
      background-size: constrain;
    }
    

    I'm not sure how this will work in the context of bootstrap, but option 2 might be your only option if you can't specify an explicit height for the image or its parent.

    There are more devils in the details and the specifics will depend on your situation, but hopefully this is helpful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀