【问题标题】:How to make Bootstrap Carousel stay fixed right below navbar?如何使 Bootstrap Carousel 固定在导航栏下方?
【发布时间】:2015-03-31 19:29:43
【问题描述】:

目前我的轮播似乎转到了页面顶部。我正在使用导航栏固定顶部,因此显然导航栏隐藏了轮播的顶部。我怎样才能使轮播保持固定在导航栏的正下方?添加一个简单的填充不起作用,因为当使用较小的屏幕时,导航栏会折叠并且与未折叠时的高度有点不同。

代码:

<div id="myCarousel" class="carousel slide" data-ride="carousel">
  <div class="container">
    <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>


    <div class="carousel-inner">
      <div class="item active">
        <img src="/images/p51blueprint.jpg" alt="P-51" width="100%">

      </div>
      <div class="item">
        <img src="/images/f-18-hornet.jpg" alt="F-18" width="100%">

      </div>
      <div class="item">
        <img src="/images/p51blackandwhite.jpg" alt="P-51" width="100%">

      </div>
      <div class="item">
        <img src="/images/B-52-Stratofortress-infographic.jpg" alt="B-52" width="100%">

      </div>
    </div>
  </div>

  <!-- Control arrows -->
  <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>

【问题讨论】:

  • 不是添加“简单”填充,而是添加带有媒体查询的主体填充?
  • @tmg 是对的。我的猜测是导航栏正在使用媒体查询来折叠。您应该弄清楚媒体查询是什么,并使用它来确定是否使用或使用了多少填充。

标签: javascript jquery css twitter-bootstrap carousel


【解决方案1】:

众所周知,导航栏会覆盖网站的内容,因此请更改主体的填充,然后使用媒体查询来更改主体的填充以适应不同的大小。大致如下:

body { 
    padding-top: 70px; 
}
@media screen and (min-width:768px) and (max-width:990px) {
  body {
    margin-top:100px;
  }
}
@media screen and (min-width:991px) and (max-width:1200px) {
  body {
    margin-top:70px;
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-14
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    相关资源
    最近更新 更多