Home > OS >  my navbar is disappearing even after having position sticky
my navbar is disappearing even after having position sticky

Time:09-27

my navbar is disappearing even after having position sticky please help me out you can check my code if u can help me out with his code please . My code was working till the about section so the div container is already change but so i did the same as about section in the forwarded/next section and this time the navbar disappeared which doesn't seems correct.

* {
  margin: 0;
  padding: 0;
  font-family: 'Montserrat', sans-serif;
}

html {
  scroll-behavior: smooth;
}


/* CSS Variables */

:root {
  --navbar-height: 59px;
}

#navbar {
  display: flex;
  align-items: right;
  position: sticky;
  top: 0px;
  justify-content: right;
}

#navbar::before {
  content: "";
  background-color: rgb(15, 15, 15);
  position: absolute;
  top: 0px;
  left: 0px;
  height: 100%;
  width: 100%;
  z-index: -1;
  opacity: 1;
}


/* Navigation Bar: Logo and Image */

#logo {
  margin: auto;
  position: sticky;
  flex-direction: row;
  align-items: center;
}

#logo h1 {
  color: rgb(255, 255, 255);
  margin: auto;
  position: sticky;
  font-size: 1.8vw;
  font-weight: 800;
  font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
  animation-name: loco;
  animation-duration: 3s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

@keyframes loco {
  0% {
    color: rgb(120, 255, 255);
  }
  25% {
    color: rgb(85, 255, 141);
  }
  50% {
    color: rgb(182, 255, 194);
  }
  75% {
    color: rgb(50, 255, 203);
  }
  100% {
    color: rgb(100, 255, 148);
  }
}


/* Navigation Bar: List Styling */

#navbar ul {
  display: flex;
}

#navbar ul li {
  list-style: none;
  font-size: 1vw;
  margin: 5px 2px;
}

#navbar ul li a {
  color: #ffffff;
  display: block;
  padding: 8px 44px;
  margin: -2px 11px;
  text-decoration: none;
  font-weight: 900;
  font-size: large;
  border-radius: 0px;
  transition: all 0.5s;
}

#navbar ul li a {
  transition-timing-function: ease-in-out;
  font-size: 1.5rem;
}

#navbar ul li a:hover {
  border-radius: 20px;
  color: rgb(0, 255, 136);
  border-radius: 20px;
  text-shadow: 0 0 10px #00ff55;
}


/* Home */

#home {
  display: flex;
  justify-content: left;
  align-items: center;
  height: 950px;
}

#home h1 {
  font-family: 'Radio Canada';
  font-size: 7vw;
  text-align: center;
  text-transform: capitalize;
  color: #FFFFFF;
  text-shadow: 5px 5px 4px #0047FF;
  margin-left: 39px;
}

#home::before {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background: url(images/traxer-4PljbcYIzyE-unsplash\ \(1\).jpg)no-repeat center center/cover;
  box-shadow: inset 529px 4px 250px 10px rgb(0, 0, 0, 90);
  filter: blur(1.5px);
  top: 0px;
  left: 0px;
  z-index: -1;
}


/*About- Section*/

#about {
  display: flex;
  align-items: center;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
}

#about::before {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background: url(/images/closeup-golden-bitcoins-dark-reflective-surface-histogram-decreasing-crypto.jpg)no-repeat center center/cover;
  box-shadow: inset 529px 4px 250px 10px rgb(0, 0, 0, 90);
  filter: blur(1.5px);
  top: 950px;
  left: 0px;
  z-index: -2;
}

#about h1 {
  /* position: absolute; */
  width: 798.53px;
  height: 78px;
  margin-top: 80px;
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 700;
  font-size: 5vw;
  line-height: 78px;
  text-align: center;
  color: #ffffff;
}

#about p {
  /* position: absolute; */
  width: 777.37px;
  height: 462px;
  margin-top: 113px;
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100;
  font-size: 2vw;
  line-height: 59px;
  text-align: center;
  color: #ffffff;
}

#about .btn {
  width: 474.93px;
  /* height: 60px; */
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 600;
  font-size: 2.4vw;
  line-height: 59px;
  text-align: center;
  justify-content: center;
  /* margin: -44px 152px 28px 152px;*/
}

#about .btn a {
  border-radius: 9px;
  color: #ffc400;
  /* background:black; */
  text-decoration: none;
  border-radius: 10px;
  text-shadow: 0px 0px 5px rgb(255, 238, 0);
  padding: 5px 5px;
  transition: all 1s;
}

#about .btn a:hover {
  background: none;
  color: rgb(0, 255, 149);
  border-radius: 10px;
  text-shadow: 0px 0px 10px rgb(0, 255, 149);
}


/* ---charts section */

#chart {
  display: flex;
}

#chart::before {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background: url(/images/maxim-hopman-fiXLQXAhCfk-unsplash.jpg)no-repeat center center/cover;
  box-shadow: inset 200px 4px 250px 10px rgb(0, 0, 0, 90);
  filter: blur(1.5px);
  top: 1920px;
  left: 0px;
  filter: brightness(0.5);
  z-index: -2;
}
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet'>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Radio Canada:wght@700&display=swap" rel="stylesheet">

<nav id="navbar">
  <div id="logo">
    <h1>All&nbsp;Crypto</h1>
  </div>
  <ul>
    <li > <a href="#home">Home</a></li>
    <li > <a href="#about">About</a></li>
    <li > <a href="#chart">Chart</a></li>
    <li > <a href="#news">News</a></li>
  </ul>
</nav>
<div id="home">
  <h1>Crypto <br> At Your <br> Fingertips</h1>
</div>
<div id="about">
  <h1>What Is CryptoCurrency</h1>
  <!-- <div id="img">
            <img src="/images/NFT_4.png" alt="">
        </div> -->
  <p>A cryptocurrency, crypto<br>currency, or crypto is a digital<br> currency designed to work as <br> a medium of exchange through<br> a computer network that is not<br> reliant on any central<br>authority.....</p>
  <div >
    <a href="#">Read More</a>
  </div>
</div>
<div id="chart">

</div>

CodePudding user response:

I think you should use position:fixed instead of position:sticky. And set the width to 100% to fit the screen. Here's the code:

#navbar {
  display: flex;
  align-items: right;
  position: fixed;
  top: 0px;
  width: 100%;
  justify-content: right;
}

CodePudding user response:

The problem is not with the #about section; it lies with the #chart section. You should have some kind of dimensions to the chart section, e.g.:

#chart {
 display:flex;
 height:100em;
}

Also, it doesn't look like you have much reason to be using a pseudo element for what looks like the image. I would recommend setting the background image to #chart, and not #chart::before.

Since your header doesn't seem to require a sticky position, please think about using position:fixed;.

  • Related