2017-10-19 169 views
0

我已经建立了几个星期的网页了。就在今天,我决定把我的导航栏部分和元标记和链接,并把它们放在母版页上。当我这样做的时候,除了一件事以外,一切都很顺利。顶部信息部分背景在底部被截断。这几乎就像我的样式表中没有读取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%; 
    } 

回答

4

height: 100%的元素永远只能是一样高我的首要信息部分它是父母。父母有多高?如果它是身体的直接孩子,请尝试在CSS中设置它:

html, body { 
    height: 100%; 
} 
+0

谢谢你这个工作。我对编码还很陌生,并不确切知道它为什么起作用。如果你不介意,你能解释一下吗? –

+3

@FinsUp当然!高度和宽度的百分比值与它们所在的容器有关。因此,400px容器的50%将是200px。当你告诉html和body元素的高度为100%时,你告诉它至少是浏览器窗口的高度,因为它具有精确的像素大小。高度层叠如下:浏览器窗口> html> body>侧边栏 – webdevdani

+0

太棒了。谢谢! –