修复用Flexbox制成的NAV栏到页面顶部,但是当您滚动滚动时,请覆盖NAV栏

发布于 2025-02-11 00:00:03 字数 1229 浏览 2 评论 0原文

因此,我创建了一个带有Flex Box的导航栏。我目前周围有一个包装纸,以便可以将其固定在顶部。此功能正常,当您加载页面时,导航栏看起来不错。但是,当您向前滚动时,Navbar将被覆盖的页面界限。我将如何避免这种情况(我在下面附上图像以表明我的意思)。

滚动之前

“ rel =“ nofollow noreferrer”>滚动后

<div class="wrapper">
    <nav>
      <a href="index.html" class="logo"><img src="assets/logo.png"></a>
      <div class ="nav-links">
        <a href="#">About</a>
        <a href="#">Portfolio</a>
        <a href="#">Contact</a>
      </div>
    </nav>
  </div>
nav {
  background-color: rgba(0,0,0,.5); /*background color*/
  height: 75px; /*height of navigation bar*/
  display: flex; /*activates flexbox properties*/
  align-items: center; /*uses flexbox to vertically center items*/
  -webkit-backdrop-filter: blur(8px); /*blurs background*/
  backdrop-filter: blur(8px); /*blurs background*/
  padding-left: 20px;
  padding-right: 20px;
  justify-content: space-between;
}

.wrapper {
  position: fixed;
  width: 100%;
}

So I created a navigation bar with flex box. I currently have a wrapper around the so that I can make it fixed to the top. This functions correctly and when you load the page the nav bar looks fine. But when you scroll up past what would be the boundaries of the page the navbar becomes covered. How would I avoid this (I have attached images below to show what I mean).

Before scroll

After scroll

<div class="wrapper">
    <nav>
      <a href="index.html" class="logo"><img src="assets/logo.png"></a>
      <div class ="nav-links">
        <a href="#">About</a>
        <a href="#">Portfolio</a>
        <a href="#">Contact</a>
      </div>
    </nav>
  </div>
nav {
  background-color: rgba(0,0,0,.5); /*background color*/
  height: 75px; /*height of navigation bar*/
  display: flex; /*activates flexbox properties*/
  align-items: center; /*uses flexbox to vertically center items*/
  -webkit-backdrop-filter: blur(8px); /*blurs background*/
  backdrop-filter: blur(8px); /*blurs background*/
  padding-left: 20px;
  padding-right: 20px;
  justify-content: space-between;
}

.wrapper {
  position: fixed;
  width: 100%;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别想她 2025-02-18 00:00:03

重置默认保证金和填充后似乎没有问题:

body {
  margin: 0;
  padding: 0;
}

Seems to be no issue after resetting default margin and padding:

body {
  margin: 0;
  padding: 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文