Bootstrap Jumbotron背景图像不响应

时间:2016-08-06 21:08:12

标签: html html5 css3 twitter-bootstrap-3 responsive-design

我是相当新的引导程序,并且很难在不显示白色背景的情况下让我的jumbotron背景图像正确缩放。我在页面顶部使用Bootstrap Fixed Nav,在中间使用Jumbotron(bg图像),使用Sticky Footer。当我在谷歌浏览器中测试以查看布局是否正确时,似乎图像不会向下延伸到页脚的顶部,这会显示白色背景。如何让所有设备正确缩放背景图像?

HTML:     

    <!-- Fixed navbar -->
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="index.html">Jason<span>Murray</span></a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li class="active"><a href="index.html">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Portfolio</a></li>
            <li><a href="#contact">Contact</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>

    <div class="jumbotron">
      <div class="container">
        <h1 class="text-center">Front-End Web Developer</h1>
        <p class="text-center">I'm Jason Murray, Front-End Web Developer who loves to write clean codes and build simplistic web designs.</p>
        <p class="text-center"><a class="btn btn-primary btn-lg" href="#" role="button">Recent Work</a></p>
      </div>
    </div>

    <footer class="footer">
      <div class="container">
        <p class="text-center">Copyright &copy; 2016 <a href="index.html" target="_blank">Jason Murray Web Design</a>. All Rights Reserved</p>
      </div>
    </footer>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

CSS:

.jumbotron {
  background: url("../img/lucho-49.jpg") no-repeat center center;
  -webkit-background-size: 100% 100%;
  -moz-background-size: 100% 100%;
  -o-background-size: 100% 100%;
  background-size: 100% 100%;
}

2 个答案:

答案 0 :(得分:2)

int urlTagStart = text.indexOf("<enclosure url=""); int urlTagEnd = text.indexOf(".mp3"); String url = text.substring(urlTagStart + 16, urlTagEnd + 4) 课程有一个保证金底部,因此请删除jumbotron

margin

这是小提琴:fiddle link

答案 1 :(得分:0)

由于jumbotron的预定义属性 margin-bottom:30px; ,图像未向下延伸到页脚顶部。

在CSS代码中执行以下更改:

nav + .jumbotron {
  margin-bottom: 0;
  background: url("../img/lucho-49.jpg") no-repeat center center;
  -webkit-background-size: 100% 100%;
  -moz-background-size: 100% 100%;
  -o-background-size: 100% 100%;
  background-size: 100% 100%;
}

如果在.jumbotron选择器中添加 margin-bottom:0; ,由于特异性,它将无法正常工作。因此,我通过添加相邻兄弟选择器,nav + .jumbotron 来增加特异性,以使用预定义的bootstrap的.jumbroton CSS属性覆盖CSS属性。