引导轮播拉伸图像

时间:2018-10-17 14:34:06

标签: html css bootstrap-4

使用引导程序时,我的轮播图片滑块的尺寸出现问题。

我尝试使用内联css更改图像的高度,但图像仍被拉伸。

<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>

<body>
  <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
    <div class="col-sm-6">
      <div class="carousel-inner">
        <div class="carousel-item active">
          <img style="min-height: 250px;" class="d-block w-100" src="images/hikvision.png" alt="First slide">
        </div>
        <div class="carousel-item">
          <img style="min-height: 250px;" class="d-block w-100" src="images/hikvision_2.png" alt="Second slide">
        </div>
        <div class="carousel-item">
          <img class="d-block w-100 h-25" src="images/hikvision_3.png" alt="Third slide">
        </div>
      </div>
      <a class="carousel-control-prev" href="#carouselExampleControls" 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="#carouselExampleControls" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>
  </div>
  <!-- Optional JavaScript -->
  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

尽管缺少图像(因为它们存储在本地计算机上),但我可以看到您使用的是最小高度。

  

min-height属性定义元素的最小高度。
  如果内容小于最小高度,则将应用最小高度。
  如果内容大于最小高度,则min-height属性无效。

w3schools
使用[max-] height,您可能会得到想要的。