html - 使用 CSS 调整固定菜单和页面内容
问题描述
我有一个固定的菜单栏,因此当用户滚动它时它仍然位于页面顶部。
但是,我想要菜单和页面之间的间隙(下面称为 pageTest)。
我尝试将 .menu 中的边距更改为
边距:0 0 50px;0;
然而什么都没有发生?我的小提琴
HTML
<body>
<div class="menu">
</div>
<div class="content">
</div>
</body>
CSS
body {
padding: 0px;
margin: 0px;
}
.menu {
background-color: #9FACEC; /* Medium blue */
position: fixed;
width: 100%;
margin: 0;
z-index: 1;
display: flex;
justify-content: center;
overflow: hidden;
height: 100px;
}
.content {
width: 90%;
margin: 0 auto;
overflow: hidden;
background-color: yellow;
height: 800px;
}
解决方案
您应该在 Menu div 中使用 top:0 并在您的情况下提供与 Nav 高度相同的边距是 100px 工作代码在这里
<body>
<div class="menu">
</div>
<div class="pageTest">
</div>
</body>
css 编辑
body {
padding: 0px;
margin: 0px;
}
.menu {
background-color: #9FACEC; /* Medium blue */
position: fixed;
width: 100%;
margin: 0;
z-index: 1;
display: flex;
justify-content: center;
overflow: hidden;
height: 100px;
top:0;
}
.pageTest {
width: 90%;
margin: 0 auto;
overflow: hidden;
background-color: yellow;
height: 800px;
margin-top:150px
}
我希望我回答了你的问题
推荐阅读
- php - 如何使用 PHP 阻止 url 中的特殊字符?
- mysql - MySQL - 可以通过 localhost 连接,但不能通过 127.0.0.1
- python - 在打印相应值时跳过特定迭代的重复值 - 我的最终目标是将其写入 CSV 文件
- node.js - 如何使用 REST API 发送 Hubspot 双重选择加入电子邮件?
- python - PySpark & MLLib:随机森林预测结果始终为 0
- python - 如何在 python 中为 Telegram 制作自动发布机器人?
- sql - 按组检查多个不同的事件
- haskell - Xmonad:将窗口从另一个工作区带到当前工作区的键绑定
- python - 替换 Python 的函数在 For 循环中不起作用
- algorithm - 朴素洗牌算法概率分析