Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
El efecto de desplazamiento de la barra de navegación no funciona cuando se tiene un color de fondo

Tengo una barra de navegación con un fondo de tipo degradado (ligeramente negro, a transparente). ingrese la descripción de la imagen aquí

Quería que la barra de navegación se volviera completamente negra al desplazarme, y escribí el código JavaScript necesario, pero el color cambia solo cuando elimino el degradado de color de fondo del CSS; de lo contrario, no funciona. ¿Existe alguna solucion para esto?

Código HTML:

 <section id="header" class="headerr"> <a href="#"><img src="images/logo.png" class="logo"></a> <div> <ul id="navbar"> <li><a class="active" href="why.html">Why Snap Smile</a></li> <li><a href="solutions.html">Solutions</a></li> <li><a href="pricing.html">Pricing</a></li> <li><a href="about.html">About</a></li> <li><a href="gallery.html">Gallery</a></li> <li><a href=""><i class="fa-solid fa-headset fa-2x"></i></a></li> </ul> </div>

Código CSS:

 body { font-family: 'Montserrat', sans-serif; width: 100%; margin: 0; background-color: #121212; } /* Header Section */ #header { display: flex; align-items: center; justify-content: space-between; padding: 10px 80px; background: rgb(0,0,0); background: linear-gradient(180deg, rgba(0,0,0,0.6629026610644257) 0%, rgba(9,9,121,0) 57%); z-index: 999; position: sticky; top: 0; left: 0; } .headerr__black{ background-color: #121212; } #navbar { display: flex; align-items: center; justify-content: space-between; } #navbar li { list-style: none; padding: 0 20px; position: relative; } #navbar li a { text-decoration: none; font-size: 1rem; font-weight: 600; color: #ffffff; transition: 200ms ease-in-out; } #navbar li a:hover, #navbar li a.active { color: #e50914; } #navbar li a.active::after, #navbar li a:hover::after { content: ""; width: 30%; height: 3px; background: #e50914; position: absolute; bottom: -6px; left: 20px; } .logo { width: 10rem; }

Código JavaScript:

 const nav=document.getElementById('header'); window.addEventListener('scroll',function(){ if(window.scrollY >= 100){ nav.classList.add('headerr__black'); } else{ nav.classList.remove('headerr__black'); } });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que esto puede suceder porque el selector #header (selector de id) tiene una prioridad más alta que .header__black (selector de clase).

¿Puede intentar actualizar su estilo para que los estilos .headerr__black tengan mayor prioridad? Por ejemplo:

 /* * Now the selector specificity is {id} + {class}, * Which is higher than just {id} for #header */ #header.headerr__black { background-color: #121212; }

Documento: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!