【问题标题】:Bootstrap Carousel - Make caption responsive to window heightBootstrap Carousel - 使标题响应窗口高度
【发布时间】:2015-06-24 13:09:51
【问题描述】:

我的页面上实现了 Bootstrap 轮播,但由于某种原因,我无法根据网络浏览器的大小重新定位标题文本。

这是我的 HTML 代码:

<!-- =======================CAROUSEL=========================== -->
<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>
  </ol>
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img class="first-slide" src="img/main-banner.png" alt="First slide">
      <div class="container">
        <div class="carousel-caption">
          <h1>Democratizing the Internet of Things!</h1>
          <p><a class="btn btn-lg btn-primary" href="./index.php?d=splash" role="button">Try Splash</a></p>
        </div>
      </div>
    </div>
    <div class="item">
      <img class="second-slide" src="img/banner-2.png" alt="Second slide">
      <div class="container">
        <div class="carousel-caption">
          <h1>Another Heading!</h1>
        </div>
      </div>
    </div>
  <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>

我正在使用 Bootstrap CDN:

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">

这些是我对轮播所做的所有 CSS 更改:

.carousel-caption {
position: relative !important;
width: 550px;
top: 210px;
left: 380px !important;
z-index: 600;
max-height:177px;

}
.carousel-caption h1 {
    font-family: sans-serif !important;
    font-size: 44px !important;
    font-weight: 700 !important;
    line-height:36px !important;    
    color: #444 !important;
    margin: 0px !important;
    padding: 0px !important;
    text-shadow: 0px 0px 4px #fff !important;
    text-align: left !important;
}

.carousel-caption p {
    margin-top: 11px !important;
    font-size:18px !important;
    line-height:21px !important;
    color:#333 !important;
    padding-bottom: 11px !important;
    margin-bottom: 11px !important;
    text-shadow: 0px 0px 4px #fff !important;
    text-align: left !important;
}

.carousel-control.left, .carousel-control.right {
    background-image: none !important;
}

.carousel-indicators {
    left: 405px !important;
}

这是轮播在全屏时的样子:

当我开始更改网络浏览器的大小时,会发生以下情况:

我尝试了所有不同类型的职位,但我终其一生都无法弄清楚我做错了什么。任何帮助表示赞赏!

【问题讨论】:

    标签: css twitter-bootstrap carousel


    【解决方案1】:

    为了使标题在中心垂直对齐,我使用了 CSS 函数 translateY 或属性 transform

    我还希望将标题直接放在左侧轮播控件旁边。

    我还删除了默认引导 CSS 添加的额外底部空间。

    .carousel-caption {
    width: 550px;
    left: 15%;
    top: 50% !important;
    transform: translateY(-50%);
    text-align: left;
    bottom: initial;
    }
    

    无论屏幕大小如何,现在都能正确显示标题:

    【讨论】:

      【解决方案2】:

      我使用

      来响应旋转木马

      @media(最大宽度:767px){ 具体尺寸款式 }

      并为该尺寸添加我的样式,我使用不同尺寸的树来对齐任何屏幕尺寸。

      【讨论】:

      • 感谢您的建议。这在技术上是可行的,但我有一个 30 英寸的显示器,我发现我必须做很多不同的尺寸。我想知道是否有一种方法可以简单地将它从父 div 的顶部居中 25% 和从左侧 25% 居中?我尝试使用 left,top: 25% ,结果与上面相同
      • 你可以试试 text-align:center;有时它会起作用
      猜你喜欢
      • 2016-07-28
      • 2018-12-30
      • 2015-12-28
      • 2017-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      • 2011-05-15
      相关资源
      最近更新 更多