Bootstrap传送带图像在IE中垂直压缩

问题描述 投票:0回答:1

我的自举传送带的固定高度为32rem,宽度为100%。当图像较大时,它将显示图像的中间部分。这在Chrome / edge / FF中效果很好。但是,在IE中,图像被垂直压缩以显示垂直空间32rem中的完整图像高度。有关如何解决此问题的任何想法?

JSBin:https://jsbin.com/cuhinecare/1/edit?html,output

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <style type="text/css">
    .row {
  background: #f8f9fa;
  margin-top: 20px;
}

.col {
  border: solid 1px #6c757d;
  padding: 10px;
}

.carousel-inner .carousel-item {
  max-height: 400px;
}
.carousel-inner .carousel-item img {
  max-width: none;
  object-fit: cover;
  overflow:hidden;

}

.carousel-caption {
  background-color:rgba(0,0,0,0.5);
}

main {min-height:460px;}


/* CUSTOMIZE THE CAROUSEL
-------------------------------------------------- */

/* Carousel base class */
.carousel {
  margin-bottom: 4rem;
}
/* Since positioning the image, we need to help out the caption */
.carousel-caption {
  bottom: 3rem;
  z-index: 10;
}

/* Declare heights because of positioning of img element */
.carousel-item {
  height: 32rem;
}
.carousel-item > img {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 100%;
  height: 32rem;
}

  </style>
</head>
<body>

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script  src="https://code.jquery.com/jquery-3.4.1.min.js"  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="  crossorigin="anonymous"></script>      
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<!-- 
  Bootstrap docs: https://getbootstrap.com/docs
-->

<main class="container">
<div id="myCarousel" class="carousel slide mb-5" data-ride="carousel">
  <ol class="carousel-indicators"><li data-target="#myCarousel" data-slide-to="0" class="active"></li><li data-target="#myCarousel" data-slide-to="1" ></li><li data-target="#myCarousel" data-slide-to="2" ></li><li data-target="#myCarousel" data-slide-to="3" ></li><li data-target="#myCarousel" data-slide-to="4" ></li>                    
  </ol>
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="https://armi.usgs.gov/uploads/20200121_111904.jpg" class="d-block w-100" alt="California Red-legged Frog eggmass arrives at a site in the Santa Ana Mountains." />
      <div class="container">
        <div class="carousel-caption">
          <h2>Story heading</h2>
          <div>By: photographer</div>                               
          <a class="btn btn-primary" href="story/story.php?contentid=202164" role="button" title="Click here to read the full story.">Read Story</a>
        </div>
      </div>
    </div>
  </div>
  <a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>      
</main>

</body>
</html>
internet-explorer bootstrap-4
1个回答
0
投票

由于object-fit: covernot supported by IE,所以图片被压缩。您可以使用background-size: cover作为解决方法。

您可以在CSS中添加此部分来处理IE 11的情况:

background-size: cover
© www.soinside.com 2019 - 2024. All rights reserved.