【问题标题】:Twitter Bootstrap carousel responsive not working rightTwitter Bootstrap轮播响应无法正常工作
【发布时间】:2015-05-26 11:06:49
【问题描述】:

好的,我有一个非常直截了当的问题,我认为不需要太多示例。基本上我有一个带有 1500px x 550px 图像的 Bootstrap Carousel,它设置为屏幕宽度的 100%。当我最小化屏幕时,图像的高度保持不变,而宽度减小使图像像被挤压在一起一样扭曲。这是我的简单轮播:

<div id="myCarousel" class="carousel slide">
  <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>
  <!-- Carousel items -->
  <div class="carousel-inner">
    <div class="active item">…</div>
    <div class="item">…</div>
    <div class="item">…</div>
  </div>
  <!-- Carousel nav -->
  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
</div>

这是我为它准备的 CSS 样式

.carousel {
      margin-bottom: 60px;
      margin-top:-16px;
    }

    .carousel .container {
      position: relative;
      z-index: 9;
    }

    .carousel-control {
      height: 80px;
      margin-top: 0;
      font-size: 120px;
      text-shadow: 0 1px 1px rgba(0,0,0,.4);
      background-color: transparent;
      border: 0;
      z-index: 10;
    }

    .carousel .item {
      height: 550px;
    }
    .carousel img {
      position: absolute;
      top: 0;
      left: 0;
      min-width: 100%;
      height: 550px;
    }

现在我尝试使用媒体查询,但它只能解决一定数量的屏幕宽度的高度问题,并且随着您不断最小化屏幕,它最终会再次变得混乱。这是我的媒体查询:

@media (max-width: 979px) {

      .container.navbar-wrapper {
        margin-bottom: 0;
        width: auto;
      }
      .navbar-inner {

        margin: 0px 0px -20px 0;
      }

      .carousel .item {
        height: 300px;
      }
      .carousel img {
        width: auto;
        height: 300px;
      }

}

 @media (max-width: 767px) {

      .carousel {
        margin-left: -20px;
        margin-right: -20px;
      }
      .carousel .container {


      }
      .carousel .item {
        height: 350px;

      }
      .carousel img {
        height: 350px;

      }


    }

只是为了让您知道我使用所有引导资产(如 responsive.css、bootstrap.min.css 和 boostrap.css)是否有任何额外帮助

【问题讨论】:

    标签: html css twitter-bootstrap responsive-design


    【解决方案1】:

    您可能想检查是否在某处设置了“最小高度”(可能在引导 css 文件之一中)。最小高度总是覆盖最大高度设置。

    【讨论】:

      【解决方案2】:

      当我遇到您的问题时,我正试图找到解决相同问题的方法,不知何故,它对我帮助很大。

      我所做的是像您一样使用媒体查询,并根据最大或最小宽度定义 carousel-inner 的高度。顺便说一句,我使用 bs3 并且轮播具有这样的 .img-responsive() 函数:

      > .item {
       display: none;
       position: relative;
       .transition(.6s ease-in-out left);
       // Account for jankitude on images
       > img,
       > a > img {
        .img-responsive();
        line-height: 1;
       }
      }
      

      这部分好像是处理图片大小调整的问题。

      【讨论】:

        【解决方案3】:

        不要添加固定高度,像这样自动设置高度

        .carousel .item { 高度:自动;

        }
        
        .carousel img {
              position: absolute;
              top: 0;
              left: 0;
              min-width: 100%;
              height: auto;
        }
        

        【讨论】:

          【解决方案4】:

          小伙子,试试这些台词。他们为我解决了问题。

          .carousel .item {
               margin: 0 auto;
                min-height: 300px;
              }
          
          .carousel-img {
              margin: 0 auto;
              min-height: 300px;
          }
          

          我不了解你,但对我来说,问题在于我的物品和里面的图片没有任何最小高度。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2018-08-17
            • 2013-04-21
            • 1970-01-01
            • 2023-03-23
            • 1970-01-01
            • 1970-01-01
            • 2014-04-06
            相关资源
            最近更新 更多