我每个人都有一个简单的问题。因此,我在页面顶部添加了一个修复导航栏,高度为44px。这部分很好。问题是,因为它具有position: fixed
,所以不在网页的流程之内。我尝试添加页边距并使用填充,但是没有用。当我使用margin-bottom: 44px;
时,向下滚动时页面底部会出现空白。
也... 我不希望页面可滚动。换句话说,我不希望查看者能够向下滚动页面,因为我添加了填充/边距。
这是我到目前为止尝试过的:
<div class="wrapper">
<nav>
<div class="container">
<ul>
<li><a href="#" class="active"><i class="fab fa-houzz"></i></a></li>
<li><a href="#">Ban</a></li>
<li><a href="#">Warn</a></li>
<li><a href="#">Gift</a></li>
<li><a href="#">User</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Reports</a></li>
<li><a href="#">Omar</a></li>
</ul>
</div>
</nav>
<div class="content">
</div>
</div>
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
-webkit-font-smoothing: antialiased;
}
.wrapper {
height: 100vh;
}
nav {
position: fixed;
top: 0;
width: 100%;
height: 44px;
overflow: scroll;
background: #323232;
}
.container {
max-width: 1000px;
margin: 0 auto;
}
nav ul {
display: flex;
height: 44px;
justify-content: space-around;
align-items: center;
padding: 0;
margin: 0;
list-style-type: none;
}
nav a {
display: block;
color: white;
font-size: 15px;
font-weight: lighter;
text-decoration: none;
transition: 0.3s;
}
nav a:hover {
color: #B8B8B8;
}
ul li:last-child a {
font-weight: normal;
}
nav ul li a.active {
color: #B7B7B7;
}
.content {
height: calc(100% - 44px);
background: red;
margin-top: 44px;
}
答案 0 :(得分:1)
box-sizing:border-box
适合您,因此添加:
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
请参阅框大小设置文档:https://www.w3schools.com/css/css3_box-sizing.asp
在.wrapper
上添加与导航栏相同大小的顶部填充,并从calc()
中删除margin-top
和.content
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
-webkit-font-smoothing: antialiased;
}
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.wrapper {
height: 100vh;
padding-top: 44px;
}
nav {
position: fixed;
top: 0;
width: 100%;
height: 44px;
overflow: scroll;
background: #323232;
}
.container {
max-width: 1000px;
margin: 0 auto;
}
nav ul {
display: flex;
height: 44px;
justify-content: space-around;
align-items: center;
padding: 0;
margin: 0;
list-style-type: none;
}
nav a {
display: block;
color: white;
font-size: 15px;
font-weight: lighter;
text-decoration: none;
transition: 0.3s;
}
nav a:hover {
color: #B8B8B8;
}
ul li:last-child a {
font-weight: normal;
}
nav ul li a.active {
color: #B7B7B7;
}
.content {
height: 100%;
background: red;
}
<div class="wrapper">
<nav>
<div class="container">
<ul>
<li><a href="#" class="active"><i class="fab fa-houzz"></i></a></li>
<li><a href="#">Ban</a></li>
<li><a href="#">Warn</a></li>
<li><a href="#">Gift</a></li>
<li><a href="#">User</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Reports</a></li>
<li><a href="#">Omar</a></li>
</ul>
</div>
</nav>
<div class="content">
</div>
</div>