在导航栏菜单图标的导航栏分隔符margin-left: auto;中添加position: fixed;:

/* Resets */

 :root {
  --pblack: #1E293B;
  --pyellow: #FFE934;
  --pwhite: white;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--pblack);
  color: var(--pwhite);
  font-family: raleway;
}

a {
  color: white;
  text-decoration: none;
}


/* Resets end */


/* Styling starts */

.logo {
  width: 32px;
  margin-right: auto;
}

.logo-type {
  display: none;
}

.container {
  margin: 1rem;
  display: flex;
  flex-direction: column;
  position: relative;
  height: 90vh;
}


/* .nav-holder { position: fixed;
} */

.navbar {
  position: fixed;
  background: transparent;
  display: flex;
  align-items: center;
  z-index: 999;
}

.nav-menu {
  position: relative;
  background: var(--pyellow);
  width: 1.5rem;
  height: 2px;
  margin-left: auto;
}

.nav-menu::before {
  content: " ";
  position: absolute;
  top: -7px;
  right: 0;
  background: var(--pyellow);
  width: .5rem;
  height: 2px;
}

.nav-menu::after {
  content: " ";
  position: absolute;
  top: 7px;
  right: 0;
  background: var(--pyellow);
  width: 1rem;
  height: 2px;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* border: 2px solid red; */
  text-align: center;
}

.greeting {
  font-size: 5rem;
  margin-bottom: 0;
}

.hero-name {
  font-size: 1.5rem;
}

.hero-anim {
  position: relative;
  margin: 6rem;
  /* border: 2px solid red; */
  width: 60%;
  /* height: 100px; */
}

.h-love {
  position: absolute;
  top: 0;
  left: 0;
}

.x-anim {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--pyellow);
  width: 2px;
  height: 1rem;
  transform: rotate(45deg);
}

.x-anim::after {
  content: "";
  display: inline-block;
  background: var(--pyellow);
  width: 2px;
  height: 1rem;
  transform: rotate(90deg);
}

.h-creating {
  position: absolute;
  top: 20px;
  left: 20px;
  font-size: 2rem;
  margin: 0;
  color: var(--pyellow);
}

.h-amazing {
  position: absolute;
  top: 65px;
  left: 45px;
}

.dash-anim {
  position: absolute;
  top: 75px;
  left: 0px;
  width: 1.5rem;
  height: 2px;
  background: var(--pyellow);
}

.h-details {
  margin-left: 3rem;
  margin-right: 3rem;
  margin-top: 10rem;
}

.know-more-btn {
  position: relative;
  border: 1px solid var(--pyellow);
  border-radius: 50px;
  padding: .5rem 2.5rem .5rem 1rem;
  width: max-content;
  display: flex;
  align-items: center;
}

.btn-arrow {
  position: absolute;
  right: 2px;
  font-size: 2rem;
}

.sect2 {
  background-color: #FFE934;
  width: 100%;
  height: 100vh;
}
<body>
  <div class="nav-holder">

  </div>
  <div class="container">
    <nav class="navbar">
      <img src="/img/Mitcho Icon black yellow.png" alt="logo" class="logo"> <span class="logo-type">Mitcho</span>
      <div class="nav-menu"></div>
    </nav>
    <main class="main-con">
      <div class="hero">
        <h1 class="greeting">Hello!</h1>
        <span class="hero-name">
                    I'm Mitchell Orutu,
                </span>
        <div class="hero-anim">
          <span class="h-love">I Love</span>
          <div class="x-anim"></div>
          <span class="h-creating">Creating</span>
          <div class="dash-anim"></div>
          <span class="h-amazing">Amazing Experiences</span>
        </div>
        <p class="h-details">A multidisciplinary designer and frontend developer. I'm obsessed with creating amazing experiences and have fun while doing it.</p>
        <a href="#" class="know-more-btn">
          <span class="know-more-text">Know More</span>
          <i class='bx bxs-chevron-right-circle btn-arrow' style='color:#ffffff'></i>
        </a>
      </div>

推荐答案

1首选解决方案

只需将right:0width: 100%;添加到.导航栏类.

.navbar {  
  position: fixed;  
  right:0;
  width:100%;
  background: transparent;
  display: flex;
  align-items: center;
  z-index: 999;  
}

/* Resets */

 :root {
  --pblack: #1E293B;
  --pyellow: #FFE934;
  --pwhite: white;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--pblack);
  color: var(--pwhite);
  font-family: raleway;
}

a {
  color: white;
  text-decoration: none;
}


/* Resets end */


/* Styling starts */

.logo {
  width: 32px;
  margin-right: auto;
}

.logo-type {
  display: none;
}

.container {
  margin: 1rem;
  display: flex;
  flex-direction: column;
  position: relative;
  height: 90vh;
}


/* .nav-holder { position: fixed;
} */

.navbar {  
  position: fixed;  
  right:0;
  width:100%;
  background: transparent;
  display: flex;
  align-items: center;
  z-index: 999;  
}

.nav-menu {
  position: relative;
  background: var(--pyellow);
  width: 1.5rem;
  height: 2px;
  margin-left: auto;
}

.nav-menu::before {
  content: " ";
  position: absolute;
  top: -7px;
  right: 0;
  background: var(--pyellow);
  width: .5rem;
  height: 2px;
}

.nav-menu::after {
  content: " ";
  position: absolute;
  top: 7px;
  right: 0;
  background: var(--pyellow);
  width: 1rem;
  height: 2px;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* border: 2px solid red; */
  text-align: center;
}

.greeting {
  font-size: 5rem;
  margin-bottom: 0;
}

.hero-name {
  font-size: 1.5rem;
}

.hero-anim {
  position: relative;
  margin: 6rem;
  /* border: 2px solid red; */
  width: 60%;
  /* height: 100px; */
}

.h-love {
  position: absolute;
  top: 0;
  left: 0;
}

.x-anim {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--pyellow);
  width: 2px;
  height: 1rem;
  transform: rotate(45deg);
}

.x-anim::after {
  content: "";
  display: inline-block;
  background: var(--pyellow);
  width: 2px;
  height: 1rem;
  transform: rotate(90deg);
}

.h-creating {
  position: absolute;
  top: 20px;
  left: 20px;
  font-size: 2rem;
  margin: 0;
  color: var(--pyellow);
}

.h-amazing {
  position: absolute;
  top: 65px;
  left: 45px;
}

.dash-anim {
  position: absolute;
  top: 75px;
  left: 0px;
  width: 1.5rem;
  height: 2px;
  background: var(--pyellow);
}

.h-details {
  margin-left: 3rem;
  margin-right: 3rem;
  margin-top: 10rem;
}

.know-more-btn {
  position: relative;
  border: 1px solid var(--pyellow);
  border-radius: 50px;
  padding: .5rem 2.5rem .5rem 1rem;
  width: max-content;
  display: flex;
  align-items: center;
}

.btn-arrow {
  position: absolute;
  right: 2px;
  font-size: 2rem;
}

.sect2 {
  background-color: #FFE934;
  width: 100%;
  height: 100vh;
}
<body>
  <div class="nav-holder">

  </div>
  <div class="container">
    
      <nav class="navbar">
        <img src="/img/Mitcho Icon black yellow.png" alt="logo" class="logo"> <span class="logo-type">Mitcho</span>
        <div class="nav-menu"></div>
      </nav>
    
    <main class="main-con">
      <div class="hero">
        <h1 class="greeting">Hello!</h1>
        <span class="hero-name">
                    I'm Mitchell Orutu,
                </span>
        <div class="hero-anim">
          <span class="h-love">I Love</span>
          <div class="x-anim"></div>
          <span class="h-creating">Creating</span>
          <div class="dash-anim"></div>
          <span class="h-amazing">Amazing Experiences</span>
        </div>
        <p class="h-details">A multidisciplinary designer and frontend developer. I'm obsessed with creating amazing experiences and have fun while doing it.</p>
        <a href="#" class="know-more-btn">
          <span class="know-more-text">Know More</span>
          <i class='bx bxs-chevron-right-circle btn-arrow' style='color:#ffffff'></i>
        </a>
      </div>
      

2解决方案

我用div包装nav标记,并为这个div分配宽度和填充.然后我删除了位置:从nav元素中固定.

/* Resets */

 :root {
  --pblack: #1E293B;
  --pyellow: #FFE934;
  --pwhite: white;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--pblack);
  color: var(--pwhite);
  font-family: raleway;
}

a {
  color: white;
  text-decoration: none;
}


/* Resets end */


/* Styling starts */

.logo {
  width: 32px;
  margin-right: auto;
}

.logo-type {
  display: none;
}

.container {
  margin: 1rem;
  display: flex;
  flex-direction: column;
  position: relative;
  height: 90vh;
}


/* .nav-holder { position: fixed;
} */

.fixed {
  position: fixed;  
  width:100%;
  padding:0px 30px 0px 0px;
}

.navbar {  
  background: transparent;
  display: flex;
  align-items: center;
  z-index: 999;  
}

.nav-menu {
  position: relative;
  background: var(--pyellow);
  width: 1.5rem;
  height: 2px;
  margin-left: auto;
}

.nav-menu::before {
  content: " ";
  position: absolute;
  top: -7px;
  right: 0;
  background: var(--pyellow);
  width: .5rem;
  height: 2px;
}

.nav-menu::after {
  content: " ";
  position: absolute;
  top: 7px;
  right: 0;
  background: var(--pyellow);
  width: 1rem;
  height: 2px;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* border: 2px solid red; */
  text-align: center;
}

.greeting {
  font-size: 5rem;
  margin-bottom: 0;
}

.hero-name {
  font-size: 1.5rem;
}

.hero-anim {
  position: relative;
  margin: 6rem;
  /* border: 2px solid red; */
  width: 60%;
  /* height: 100px; */
}

.h-love {
  position: absolute;
  top: 0;
  left: 0;
}

.x-anim {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--pyellow);
  width: 2px;
  height: 1rem;
  transform: rotate(45deg);
}

.x-anim::after {
  content: "";
  display: inline-block;
  background: var(--pyellow);
  width: 2px;
  height: 1rem;
  transform: rotate(90deg);
}

.h-creating {
  position: absolute;
  top: 20px;
  left: 20px;
  font-size: 2rem;
  margin: 0;
  color: var(--pyellow);
}

.h-amazing {
  position: absolute;
  top: 65px;
  left: 45px;
}

.dash-anim {
  position: absolute;
  top: 75px;
  left: 0px;
  width: 1.5rem;
  height: 2px;
  background: var(--pyellow);
}

.h-details {
  margin-left: 3rem;
  margin-right: 3rem;
  margin-top: 10rem;
}

.know-more-btn {
  position: relative;
  border: 1px solid var(--pyellow);
  border-radius: 50px;
  padding: .5rem 2.5rem .5rem 1rem;
  width: max-content;
  display: flex;
  align-items: center;
}

.btn-arrow {
  position: absolute;
  right: 2px;
  font-size: 2rem;
}

.sect2 {
  background-color: #FFE934;
  width: 100%;
  height: 100vh;
}
<body>
  <div class="nav-holder">

  </div>
  <div class="container">
    <div class="fixed">
      <nav class="navbar">
        <img src="/img/Mitcho Icon black yellow.png" alt="logo" class="logo"> <span class="logo-type">Mitcho</span>
        <div class="nav-menu"></div>
      </nav>
    </div>
    <main class="main-con">
      <div class="hero">
        <h1 class="greeting">Hello!</h1>
        <span class="hero-name">
                    I'm Mitchell Orutu,
                </span>
        <div class="hero-anim">
          <span class="h-love">I Love</span>
          <div class="x-anim"></div>
          <span class="h-creating">Creating</span>
          <div class="dash-anim"></div>
          <span class="h-amazing">Amazing Experiences</span>
        </div>
        <p class="h-details">A multidisciplinary designer and frontend developer. I'm obsessed with creating amazing experiences and have fun while doing it.</p>
        <a href="#" class="know-more-btn">
          <span class="know-more-text">Know More</span>
          <i class='bx bxs-chevron-right-circle btn-arrow' style='color:#ffffff'></i>
        </a>
      </div>
      

Html相关问答推荐

为什么在这种情况下是弹性基础:自动不解决内容的大小?

如何在angular 17.2中使用routerLink解决此错误

Angular Project中的星级 Select

使用css第n个子元素,如何迭代Y组中的X个元素?

当文本添加到元素中时,将元素拉到页面上

在Vue 3中使用v-Bind将计算(computed)属性传递给css url()

禁用的文本区域会丢失换行符

如何生成随机字符串的字母数字字符集长度到html跨度?

如何在ASP.NET Core中添加换行符

根据Tailwind CSS中的子计数而非子宽度进行对齐,并水平对齐

Swift WKUserContentController 和 WKScriptMessageHandler 设置不正确

如何使粘性导航栏能够跨其他组件工作?

将箭头图标添加到工具提示包装器时遇到问题

需要帮助个性化我的 CSS 导航栏:如何在鼠标悬停时突出显示
  • 元素?
  • CSS 网格跨度行到所有行

    标签背景 colored颜色 的 html 和 css 技巧说明

    th 内的 div 标签没有占据全高

    鼠标悬停时切换 colored颜色 的双色链接

    我正在使用 react-router-dom 并创建了一个固定的导航栏,它在每个网页上不断改变大小,我不知道为什么

    无法在 css 的 body 标签中正确呈现(内联显示)