【问题标题】:controlling the height of the carousel size控制轮播大小的高度
【发布时间】:2015-03-13 22:07:24
【问题描述】:

我正在努力确保我的旋转木马尺寸在高度方面保持不变。我使用不同的图像,我知道图像大小不同,但不知道如何控制图像的高度。无论图像大小如何,我都希望我的轮播高度保持不变,那么我该如何控制呢?这是我正在使用的代码:

<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">
        <%--<img src="img_chania.jpg" alt="Chania" width="460" height="345">--%>
          <img src="img/sleep1.jpg" alt="Chania" width="460" height="345" />
          <div class="carousel-caption">
              <h1>Example headline.</h1>
              <p>this is test </p>
         </div>
      </div>

      <div class="item">
       <%-- <img src="img_chania2.jpg" alt="Chania" width="460" height="345">--%>
          <img src="img/image5.jpg" alt="Chania" width="460" height="345"/>

      </div>

      <div class="item">
        <%--<img src="img_flower.jpg" alt="Flower" width="460" height="345">--%>
          <img src="img/nature3.jpg" alt="Chania" width="460" height="145" />
          <div class="carousel-caption">
              <h1>Example headline.</h1>
              <p>this is test </p>
         </div>
      </div>

      <div class="item">
        <%--<img src="img_flower2.jpg" alt="Flower" width="460" height="345">--%>
          <img src="img/nature2.jpg" alt="Chania" width="460" height="245"/>
      </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>

【问题讨论】:

  • item 类上设置高度height: 400px; - 就这么简单。您还应该包含所有相关代码 (CSS)。
  • 谢谢Ruddy,这就是你的意思: 吗?我并没有真正关注..
  • 我猜你几乎没有网络开发经验。你应该四处看看,因为这种事情是非常基本的。 &lt;img src="img/image5.jpg" alt="Chania" width="460" height="400px"/&gt; 是你想要做的。如果您想将图像设置为该高度。
  • 我试过还是不行

标签: html css twitter-bootstrap twitter-bootstrap-3 carousel


【解决方案1】:

.item 类上添加一些自定义 CSS 来覆盖 Bootstraps 核心 CSS,如下所示:

 <style>
 .carousel-inner > .item > img,
 .carousel-inner > .item > a > img {
     display: block;
     max-width: 100%;
     height: 400px !important;
 }
 </style>

这将使轮播大小为 400 像素。

默认情况下,高度设置为自动,但由于我们不希望这样,我们手动设置大小并说它是!important,因此浏览器知道这种样式推翻了之前设置的引导 css。

我希望这会有所帮助并且有意义。

【讨论】:

  • 感谢 Jason,解决了高度问题,但现在宽度变小了,之前宽度与轮播大小相同。请帮忙。谢谢
  • 嗯,尝试将宽度设置为某个所需的宽度。或者尝试将其设置为自动。
【解决方案2】:

我通过将这段代码添加到标签中解决了这个问题

<div id="Div1" class="carousel" runat="server" style="height:800px !important;">

它会自动增加尺寸,如果你也想增加宽度。 谢谢你

【讨论】:

    猜你喜欢
    • 2012-12-27
    • 1970-01-01
    • 2015-03-13
    • 2018-02-25
    • 2015-04-19
    • 1970-01-01
    • 2020-03-20
    • 2013-10-29
    • 2023-03-11
    相关资源
    最近更新 更多