html - 背景图片不会填满屏幕

标签 html css twitter-bootstrap

我已经设置我的网页几个星期了。就在今天,我决定将我的导航栏部分、元标记和链接放在母版页上。当我这样做时,除了一件事之外,一切都很顺利。顶部信息部分背景在底部被截短。这几乎就像它没有读取我的样式表中的 height: 100% 一样。这是我的母版页,我将一些内容移到了其中。

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    @rendersection("prehead",false)

    <title>
        @viewdata("title")
    </title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link href="//fonts.googleapis.com/css?family=Roboto:100,400,400i,700" rel="stylesheet">
    <link rel="stylesheet" href="~/CMS_Static/CSS/floridaVisionsStyles.css">

  </head>
  <body>

    <nav class="navbar navbar-default top-of-page">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <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="#"><img src='/CMS_Static/Uploads/313864614C6F6F/fv-logo-3.gif' align="left"/></a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul id="navLinks" class="nav navbar-nav">
        <li><a href="#">Home</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Locations</a></li>
        <li><a href="#">Prices</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </div>
  </div>
</nav>

@renderbody()

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>    

  <script>  $(window).on("scroll", function() {
    var scrollPos = $(window).scrollTop();
    if (scrollPos <= 0) {
        $('.navbar-default').addClass('top-of-page');
    } else {
        $('.navbar-default').removeClass('top-of-page');
    }
});
   </script>
   @renderSection("scripts",false)
  </body>
</html>

这是我的顶级信息部分,背景被截断

<section class="topInfo">
    <div class="container">
        <div class="row">
            <div class="col-md-10 col-md-offset-1">
                <h1 class="topInfoText text-center">Aerial Drone Services, Stock Footage, and Affordable Prints</h1>
            </div>
            <div class="col-sm-4 col-sm-offset-4">
                 <a class="btn bannerBtn btn-block" href="#">Learn More</a>
            </div>
        </div>
    </div>
</section>

以及 topInfo 类的样式

.topInfo {
        background-image: linear-gradient( rgba(0,0,0,.25), rgba(0,0,0,.25) ), url('/CMS_Static/Uploads/313864614C6F6F/exuma rocks 2.jpg');
        background-attachment: fixed;
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
        height: 100%;
    }

最佳答案

具有 height: 100% 的元素只能与其父元素一样高。 parent 多高?如果它是 body 的直接子项,请尝试在您的 CSS 中进行设置:

html, body {
   height: 100%;
}

关于html - 背景图片不会填满屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46821822/

相关文章:

javascript - ContentTools - 如何将附加数据从 DIV 传递到有效负载对象,以传递到 POST 数组?

javascript - 一闪而过的内容

css - Bootstrap 3 - 没有插入符号和上圆 Angular 的下拉登录表单

javascript - 如何让一个函数仅在另一个函数完全启动后才启动?

javascript - 如何制作多个可移动元素

javascript - 在 javascript 中选择特定表格元素的最聪明的方法是什么?

jquery - Bootstrap 4 导航栏下拉菜单项在移动设备上不可点击

html - 在 Bootstrap 中更改图像的堆叠顺序

php - 将类添加到 jquery 中的事件列表项

jquery - Bootstrap 3 动画列大小调整