简体   繁体   English

在指定的列引导程序3中按比例缩放图像比例

[英]image scale proportionally within specified column bootstrap 3

I'm trying to get image fit with bootstrap column in a row proportionally within specified height 300px, i have tried so many ways but unfortunately its not fit with column width (my 1st image dimension is 262*380 and 2nd image dimension 546*380 and im using img-responsive class) 我正在尝试使引导栏的图像在指定高度300px内成比例地排列,我尝试了很多方法,但不幸的是它不适合列宽(我的第一个图像尺寸为262 * 380,第二个图像尺寸为546 * 380和即时通讯使用img-response类

I need my image should be like this Expected 我需要我的形象应该是这样的预期

but im getting like this Actual 但即时得到这样的实际

My HTML 我的HTML

<div class="container">
  <div class="row">
    <div class="col-md-4">
      <div class="grid">
        <img src="https://static5.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lunch-5502ae26.jpg" class="img-responsive" alt="">
      </div>
    </div>
    <div class="col-md-8">
      <div class="grid">
        <img src="https://static7.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lounge-0cd3d802.jpg" class="img-responsive" alt="">
      </div>
    </div>
  </div>

My CSS 我的CSS

.grid {
  height: 300px;
  border-right: 4px;
}

.grid img {
  height: 100%;
}

Try this HTML: 试试这个HTML:

<div class="container">
  <div class="row">
    <div class="col-md-4 bg-cover grid" style="background-image: url(https://static5.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lunch-5502ae26.jpg)">
    </div>
    <div class="col-md-8 bg-cover grid" style="background-image: url(https://static7.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lounge-0cd3d802.jpg)">
    </div>
  </div>
</div>

with this CSS: 使用此CSS:

.grid {
  height: 300px;
}

.grid img {
  height: 100%;
}
.bg-cover {
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  height: 300px
}

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

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