簡體   English   中英

Bootstrap 旋轉木馬圖像在 IE 中垂直壓縮

[英]Bootstrap carousel images compressed vertically in IE

我的 bootstrap carousel 的固定高度為 32rem,寬度為 100%。 當圖像較大時,它顯示圖像的中間部分。 這在 Chrome/edge/FF 中運行良好。 然而,在 IE 中,圖像被垂直壓縮以在 32rem 的垂直空間中顯示完整的圖像高度。 有想法該怎么解決這個嗎?

<!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="images/img_113404.jpg" class="d-block w-100" alt="" />
      <div class="container">
        <div class="carousel-caption">
          <h2>Story heading</h2>
          <div>By: photographer</div>                               
          <a class="btn btn-primary" href="#" 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>

圖片被壓縮是因為IE 不支持object-fit: cover 您可以使用background-size: cover作為解決方法。

你可以在 CSS 添加這部分來處理 IE 11 的情況:

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    /* IE10+ CSS */
    .carousel-item.active {
        background-image: url(https://armi.usgs.gov/uploads/20200121_111904.jpg);
        background-size: cover;
        background-position: 50% 45%;
     }
     .carousel-item img {
        display:none !important;

     }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM