【发布时间】:2019-07-29 22:15:48
【问题描述】:
我使用来自 Boostrap 的粘性页脚导航栏模板作为起点,并尝试将灰色 div 设置为 120 像素的固定高度,而蓝色 div 占据剩余高度。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="../../../../favicon.ico">
<title>Sticky Footer Navbar Template for Bootstrap</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link href="sticky-footer-navbar.css" rel="stylesheet">
</head>
<body>
<header>
<!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">Fixed navbar</a>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
</header>
<!-- Begin page content -->
<div class="container-fluid">
<div class="row bg-primary d-flex flex-1 flex-column">
ermentum, tortor tellus ultricies erat, et ultricies magna nisi at
</div>
<div class="row bg-secondary flex-0" style="height:120px;">
</div>
</div>
<footer class="footer">
<div class="container">
<span class="text-muted">Place sticky footer content here.</span>
</div>
</footer>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
和css文件
html {
position: relative;
min-height: 100%;
}
body {
/* Margin bottom by footer height */
margin-bottom: 40px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 40px;
line-height: 40px; /* Vertically center the text there */
background-color: #f5f5f5;
}
body > .container-fluid {
padding: 50px 15px 0;
}
.footer > .container {
padding-right: 15px;
padding-left: 15px;
}
我还尝试采用我找到的代码表单 codepen 并将其粘贴到模板中并调整 CSS,但我从未让它工作。
【问题讨论】:
-
bootstrap 缺少sticky-bottom,您可以在样式表中使用 position:sticky,旧浏览器不会受到伤害。您需要的大部分内容都可以通过课程来告知。例如codepen.io/gc-nomade/pen/JzNdaM
标签: css twitter-bootstrap flexbox sticky-footer