我有以下引导滑块

<div id="demo" class="carousel slide" data-ride="carousel">

  <!-- Indicators -->
  <ul class="carousel-indicators">
    <li data-target="#demo" data-slide-to="0" class="active"></li>
    <li data-target="#demo" data-slide-to="1"></li>
    <li data-target="#demo" data-slide-to="2"></li>
  </ul>

  <!-- The slideshow -->
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="la.jpg" alt="Los Angeles" width="100%" height="100%">
    </div>
    <div class="carousel-item">
      <img src="chicago.jpg" alt="Chicago" width="100%" height="100%">
    </div>
    <div class="carousel-item">
      <img src="ny.jpg" alt="New York" width="100%" height="100%">
    </div>
  </div>

  <!-- Left and right controls -->
  <a class="carousel-control-prev" href="#demo" data-slide="prev">
    <span class="carousel-control-prev-icon"></span>
  </a>
  <a class="carousel-control-next" href="#demo" data-slide="next">
    <span class="carousel-control-next-icon"></span>
  </a>
</div>


我有不同高度的图像,如何使用封面功能使所有具有相同高度和宽度的图像适合边框并具有封面中心效果?

https://www.w3schools.com/cssref/playit.asp?filename=playcss_background-size&preval=cover

最佳答案

这是答案

<div id="demo" class="carousel slide" data-ride="carousel">

  <!-- Indicators -->
  <ul class="carousel-indicators">
    <li data-target="#demo" data-slide-to="0" class="active"></li>
    <li data-target="#demo" data-slide-to="1"></li>
    <li data-target="#demo" data-slide-to="2"></li>
  </ul>

  <!-- The slideshow -->
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="la.jpg" alt="Los Angeles" width="100%" style="object-fit: cover; object-position: 50% 50%; height: 60vh">
    </div>
    <div class="carousel-item">
      <img src="chicago.jpg" alt="Chicago" width="100%" style="object-fit: cover; object-position: 50% 50%; height: 60vh">
    </div>
    <div class="carousel-item">
      <img src="ny.jpg" alt="New York" width="100%" style="object-fit: cover; object-position: 50% 50%; height: 60vh">
    </div>
   </div>

  <!-- Left and right controls -->
  <a class="carousel-control-prev" href="#demo" data-slide="prev">
     <span class="carousel-control-prev-icon"></span>
  </a>
  <a class="carousel-control-next" href="#demo" data-slide="next">
     <span class="carousel-control-next-icon"></span>
  </a>
 </div>


注意:object-git不适用于IE,而object-position center center不适用于所有浏览器

关于css - 滑块内的图像盖,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53968590/

10-11 20:06