滑块内的图像盖

时间:2018-12-29 10:12:17

标签: css image slider 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%" 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

1 个答案:

答案 0 :(得分:0)

这是答案

<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在所有浏览器上都不起作用