固定高度适用于任何设备的滑块

时间:2017-04-29 03:36:40

标签: html css twitter-bootstrap

我正在尝试为任何设备实现全屏选项。有一个滑块和04个盒子和&我试图在任何设备上全屏显示所有这些。我几乎已经通过使用.carousel-inner {min-height:83vh;} .carousel-inner img{max-height:83vh;}来实现它,但是它可以拉伸图像。我需要一个更好的解决方案。



.container-fluid {
  margin:0;
  Padding:0;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">


<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
    <li data-target="#carousel-example-generic" data-slide-to="1"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img src="http://logohour.com/images/bg2.jpg" alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    <div class="item">
      <img src="http://logohour.com/images/bg3.jpg" alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" 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="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

<div class="container-fluid">
<div class="col-xs-3">
<img src="http://placehold.it/150x75/111111" alt="...">
</div>
<div class="col-xs-3">
<img src="http://placehold.it/150x75/333333" alt="...">
</div>
<div class="col-xs-3">
<img src="http://placehold.it/150x75/666666" alt="...">
</div>
<div class="col-xs-3">
<img src="http://placehold.it/150x75/999999" alt="...">
</div>
</div>
<br><br>




<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

仅在css中写这个

.carousel-inner > .item > img {
  height:500px;
}

如果我使用提供的类,所以它也影响宽度,但是当我在你的班级使用min-height时它的工作正常,但仅限于笔记本电脑和小屏幕尺寸,但也拉伸。它不适用于大屏幕

答案 1 :(得分:0)

Plz使用它

<script>
$( document ).ready(function() {
       function mySlider() {
       var winH = $(window).height();
       var winW = $(window).width();
       var fourBoxH = $('#fourBox').height();
       var finalSliderH = winH - fourBoxH;
        $('.carousel-inner').css( {'height' : finalSliderH+'px', 'width' : winW+'px',  });
   };
   window.onload = mySlider();
});
</script>

css&gt;&gt;

.carousel-inner { }
.carousel-inner img { width:100% }

在4盒容器上添加id&gt;&gt;

<div class="container-fluid" id="fourBox">