为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的导航栏没有固定在其位置?

为什么我的导航栏没有固定在其位置?

萧十郎 2023-12-19 10:39:39
我已经制作了一个对角滚动页面,但是当我应用插件使其以这种方式滚动时,导航栏不再固定,加上我的部分不居中,我的意思是它们是垂直显示的,而不是对角线,我不知道如何以这种方式显示它们,有什么解决方案吗?我的首要任务是导航栏,但如果我能在一个问题中解决这两件事,那就更好了。感谢社区!<link href="https://fonts.googleapis.com/css2?family=Archivo+Black&family=Montserrat:wght@900&display=swap" rel="stylesheet"><meta charset="utf-8"><title>Subworld Productions</title><!-- <link rel="stylesheet" href="css/styles.css">--><body data-0="transform:translateX(0%)" data-4000="transform:translateX(-300%)">  <header>    <nav>      <img src="Graphic logo.png" alt="Subworld Productions">      <ul class="nav-links">        <li><a href="#home">Home</a></li>        <li><a href="#portfolio">Portfolio</a></li>        <li><a href="#submit">Submit</a></li>        <li><a href="#contact">Contact</a></li>        <li><a href="#about">About</a></li>      </ul>      <div class="burger">        <div class="line1"></div>        <div class="line2"></div>        <div class="line3"></div>      </div>    </nav>    <section id="home">      <h1>HOME PAGE</h1>      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
查看完整描述

1 回答

?
繁花如伊

TA贡献2012条经验 获得超12个赞

您的 CSS 存在一些问题。第一个是您对导航链接属性有多个声明。我对它们进行了分组并调整了它们(稍后会详细介绍)我还整理了你的CSS以按顺序放置你的CSS:首先是导航链接,然后是导航链接li,然后是导航链接li a等,因为CSS是按这个顺序读取的。你在一个 css 类中有 display:flex; 和 position:absolute - 这些冲突,我删除了绝对定位。

然而,真正抛弃你的ul,使链接不可见的是translateX——将你的链接翻译100%,就是将你的链接移出视线。我把这个注释掉了。按原样(现在)您的链接显示,悬停时动画,单击时滚动到适当的部分。另请注意:您的部分中的网址后面有两个分号。我在您发布的代码和片段代码中更正了这一点。

希望这可以帮助


* {

  margin: 0px;

  padding: 0px;

  box-sizing: border-box;

  scroll-behavior: smooth;

  scroll-snap-type: y mandatory;

}


body {

  background-color: #900c3f;

  font-family: Montserrat;

  height: 100vh;

  color: #F5F5F5;

  overflow: hidden;

  overflow-y: scroll;

  scroll-behavior: smooth;

}


img {

  width: 130px;

  margin-top: 20px;

  margin-left: 20px;

  margin-bottom: 20px;

}


nav {

  width: 100%;

  position: fixed;

  display: flex;

  justify-content: space-around;

  align-items: center;

  min-height: 8vh;

  background-color: #ff5733;

}


.nav-links {

  display: flex;

  justify-content: space-around;

  width: 80%;

  /*   position: absolute;

  right: 0px;*/

  height: 10vh;

  top: 17vh;

  background-color: #ff5733;

  flex-direction: row;

  font-size: 80%;

  align-items: center;

  /*transform: translateX(100%);*/

  transition: transform 0.5s ease-in;

}


.nav-links li {

  list-style: none;

  color: #ffffff;

}


.nav-links li a {

  display: inline-block;

  color: #ffffff;

}


.nav-links li a:after {

  content: '';

  width: 0;

  height: 5px;

  display: block;

  background: #F5F5F5;

  transition: 300ms;

  border-radius: 5px;

}


.nav-links li a:hover:after {

  width: 100%;

}


.nav-links li {

  opacity: 1;

}


.burger {

  display: block;

}



@keyframes navLinkFade {

  from {

    opacity: 0;

    transform: translateX(50px);

  }

  

  to {

    opacity: 1;

    transform: translateX(0px);

  }

}

.nav-active {

  transform: translateX(0%);

}

section {

  display: flex;

  flex-direction: column;

  align-items: center;

  justify-content: center;

  text-align: center;

  width: 100%;

  height: 100vh;

  scroll-snap-align: center;

}

section h1 {

  font-size: 4rem;

  justify-content: center;

  align-items: center;

}

section p {

  font-size: 1.5rem;

  justify-content: center;

  align-items: center;

}


/* Section Images */

section#home {

  background: url('https://source.unsplash.com/bZZp1PmHI0E/1600x900') no-repeat center center/cover;

}

section#portfolio {

  background: url('https://source.unsplash.com/VRxo0yY-gyM/1600x900') no-repeat center center/cover;

}

section#submit {

  background: url('https://source.unsplash.com/K2tdx2mFDHc/1600x900') no-repeat center center/cover;

}

section#contact {

  background: url('https://source.unsplash.com/2aAHlfDOhJM/1600x900') no-repeat center center/cover;

}

section#about {

  background: url('https://source.unsplash.com/user/erondu/1600x900') no-repeat center center/cover;

}

<link href="https://fonts.googleapis.com/css2?family=Archivo+Black&family=Montserrat:wght@900&display=swap" rel="stylesheet">

<meta charset="utf-8">

<title>Subworld Productions</title>

<!-- <link rel="stylesheet" href="css/styles.css">-->



<body data-0="transform:translateX(0%)" data-4000="transform:translateX(-300%)">

  <header>

    <nav>

      <img src="Graphic logo.png" alt="Subworld Productions">

      <ul class="nav-links">

        <li><a href="#home">Home</a></li>

        <li><a href="#portfolio">Portfolio</a></li>

        <li><a href="#submit">Submit</a></li>

        <li><a href="#contact">Contact</a></li>

        <li><a href="#about">About</a></li>

      </ul>

      <div class="burger">

        <div class="line1"></div>

        <div class="line2"></div>

        <div class="line3"></div>

      </div>

    </nav>

    <section id="home">

      <h1>HOME PAGE</h1>

      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure

        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

    </section>

    <section id="portfolio">

      <h1>PORTFOLIO PAGE</h1>

      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure

        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

    </section>

    <section id="submit">

      <h1>SUBMIT PAGE</h1>

      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure

        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

    </section>

    <section id="contact">

      <h1>CONTACT PAGE</h1>

      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure

        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

    </section>

    <section id="about">

      <h1>ABOUT PAGE</h1>

      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure

        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

    </section>

  </header>

  <!-- <script src="javascript/app.js"></script>

  <script src="skrollr.js"></script>-->

  <script src="http://prinzhorn.github.io/skrollr/dist/skrollr.min.js">

    skrollr.init();

  </script>

</body>


查看完整回答
反对 回复 2023-12-19
  • 1 回答
  • 0 关注
  • 106 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信