我已经将我的网页设置了几个星期了。就在今天,我决定使用我的导航栏部分和元标记和链接,并将它们放在母版页上。当我这样做时,一切顺利,除了一件事。顶部信息部分背景在底部短缺。这几乎就像它没有在我的样式表中阅读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%;
}
答案 0 :(得分:4)
height: 100%
元素只能与父元素一样高。父母有多高?如果它是身体的直接孩子,请尝试在CSS中设置:
html, body {
height: 100%;
}