【问题标题】:How to decrease the height of images in Bootstrap 4?如何降低 Bootstrap 4 中图像的高度?
【发布时间】:2020-07-04 22:29:17
【问题描述】:

我想稍微降低高度,以便图像更适合我的页面。 我的意思的一个例子:

我尝试使用自定义 CSS 来更改高度,但我的图像看起来很奇怪而且不合适。

我的 HTML:

   <!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

 <!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>

<div class="container-fluid p-0 mt-2">
      <div class="row ">
        <div class="col-md-6 col-12 p-0">
          <img class="img-fluid" src="https://images.pexels.com/photos/2187605/pexels-photo-2187605.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260">
        </div>
        <div class="col-md-6 col-12 p-0">
          <img class="img-fluid" src="https://images.pexels.com/photos/2187622/pexels-photo-2187622.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
      </div>

【问题讨论】:

  • 你说的尺寸是指每张图片的宽度和高度?
  • 你想并排对齐图像吗?
  • 宽度很好,因为它应该占用 50/50 的空间,但图像的高度相当大。我想像示例图像中那样使图像高度更小。如果您全屏运行代码 sn-p,您将看到图像很大。我希望这足以解释我仍然是初学者,所以如果有不清楚的地方,我很抱歉!

标签: html css bootstrap-4


【解决方案1】:

这可能就是你要找的东西

.h-200 {
  height: 200px;
}

img.image {
    height: 100%;
    object-fit: cover;
    width: 100%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid p-0 mt-2">
  <div class="row ">
    <div class="col-md-6 col-12 p-0 h-200">
      <img class="img-fluid image" src="https://images.pexels.com/photos/2187605/pexels-photo-2187605.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260">
    </div>
    <div class="col-md-6 col-12 p-0 h-200">
      <img class="img-fluid image" src="https://images.pexels.com/photos/2187622/pexels-photo-2187622.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260">
  </div>

链接到小提琴https://jsfiddle.net/6hpsoynf/1/

【讨论】:

    猜你喜欢
    • 2017-08-23
    • 1970-01-01
    • 2012-04-20
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    相关资源
    最近更新 更多