gpt4 book ai didi

css - bootstrap 4 flex 粘性页脚和固定顶部导航栏

转载 作者:行者123 更新时间:2023-11-28 00:16:58 26 4
gpt4 key购买 nike

我使用 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,但我从来没有让它工作过。

最佳答案

[ 1]是上面发布的代码在浏览器中的样子

当蓝色 div 的高度小于屏幕高度时,我希望得到如下图所示的结果 - 40px 粘性页脚和 120px 灰色 div。
[ 2]

当蓝屏内容大于屏幕高度时,根据需要显示滚动条,并让粘性页脚作为普通页脚显示在 120px 灰色 div 下方。

关于css - bootstrap 4 flex 粘性页脚和固定顶部导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55053753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com