gpt4 book ai didi

css - 指定 div 高度( Bootstrap )

转载 作者:可可西里 更新时间:2023-11-01 13:48:36 26 4
gpt4 key购买 nike

所以我正在尝试使用 Bootstrap 制作一个很酷的投资组合登陆页面。

该模板包括一个固定的导航栏和一个粘性页脚。页面的其余部分是我想要填充的空白,基本上是一个巨大的背景,所以我放了一个测试段落元素来尝试看看如何调整它的大小。我想我可以只添加 CSS 规则使 body 的高度为 100%,但是当我这样做时我得到了溢出并且我的页脚不再位于页面底部。相反,我在底部有一点背景溢出。

我该如何解决这个问题?我将背景颜色设为亮黄色以尝试展示我的意思。感谢您的帮助!

这是 HTML

<!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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Work in Progress</title>
</head>

<body>
<!--navbar-->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed"
data-toggle="collapse" data-target="#navbar"
aria-expanded="false" aria-controls="navbar">
<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="#">Portfolio</a>
</div>
<div id="navbar" class="navbar-collapse collapse"
aria-expanded="false" style="height: 1px;">
<ul class="nav navbar-nav">
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"
role="button" aria-haspopup="true"
aria-expanded="false">Projects
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Rails Projects</a></li>
<li><a href="#">LAMP Projects</a></li>
</ul>
</ul>
</div>
</div>
</nav>


<div class="main">
<div class="container">
<p>Test text</p>
</div>
</div>



<!--footer-->
<footer class="footer">
<div class="container">
<div class="row">
<div class="col-md-4">
<p>Contact info or whatever goes here.</p>
</div>
<div class="col-md-4 col-md-offset-4">
<p>More info or whatever goes here.</p>
</div>
</div>
</div>
</footer>


</body>
</html>

这是 CSS

html, body{
height: 100%
}

.main{
height: 100%;
background-color: #FFFF00;
margin-top: 50px;
}

.footer{
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
background-color: #000;
color: #9d9d9d;
}

最佳答案

您可以使用此 CSS(position: relative 在正文和 .main 高度作为计算函数(100% 减去页脚高度):

html,
body {
height: 100%;
position: relative;
}
.main {
height: calc(100% - 60px);
background-color: #FFFF00;
padding-top: 50px;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
background-color: #000;
color: #9d9d9d;
}

关于css - 指定 div 高度( Bootstrap ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38285473/

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