固定的高度和宽度,用于响应式引导轮播

时间:2018-07-24 13:09:07

标签: jquery html css

我正在尝试创建响应式轮播,但是图片的宽度和高度不同,并且由于移动版本而无法使用像素。

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <h2>Carousel Example</h2>
  <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <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>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner">
      <div class="item active">
        <img src="http://via.placeholder.com/350x150" style="width:100%">
      </div>

      <div class="item">
        <img src="http://via.placeholder.com/350x150" style="width:100%">
      </div>

      <div class="item">
        <img src="http://via.placeholder.com/350x150" alt="New york" style="width:100%;">
      </div>
    </div>

    <!-- Left and right controls -->
    <a class="left carousel-control" href="#myCarousel" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</div>

2 个答案:

答案 0 :(得分:1)

我建议您尝试避免使用内嵌样式。您如何尝试使用:

procedure Test;
var
  iBaseClass : TBaseClass;
  iStringStuff : TStringStuff;
  iNumStuff : TNumStuff;
begin
  iBaseClass := TBaseClass.Create;
  iStringStuff := TStringStuff.Create;
  iNumStuff := TNumStuff.Create;
end;

用于增加图像的宽度。

也许添加

.item img{
width: 100%;
}

转盘。

答案 1 :(得分:1)

尝试使用此方法添加不同大小的图像,以固定的height:500px

进行查看

.carousel-inner .item{
height:500px;
background-size:cover;
background-position: center center;
}
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <br>
  <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <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>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
      <div class="item active" style="background-image: url(//placehold.it/1024x700)  ">
      </div>

      <div class="item" style="background-image: url(//placehold.it/100x100)  ">
      </div>

      <div class="item" style="background-image: url(//placehold.it/1024x700)  ">
      </div>

      <div class="item" style="background-image: url(//placehold.it/200x200)  ">
      </div>
    </div>

    <!-- Left and right controls -->
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</div>