gpt4 book ai didi

html - 固定导航栏重叠内容(使用边距使页面可滚动,我不希望这样)

转载 作者:太空宇宙 更新时间:2023-11-04 07:10:03 25 4
gpt4 key购买 nike

我有一个简短的问题大家。所以我在页面顶部添加了一个高度为 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;
}

最佳答案

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>

关于html - 固定导航栏重叠内容(使用边距使页面可滚动,我不希望这样),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51256717/

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