Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

73
Vistas
flexbox is misbehaving with javascript active class

Navbar Beginner here As you can see everything is working perfectly until you click on the space between the links you can check here- my codepen. when I click on the links navbar it perfectly shows the active class, but if I click in between the space the whole navbar loses the class.

var element = document.getElementsByClassName("flex-nav")[0];
element.addEventListener("click", myFunction);
function myFunction(e) {
  var elems = document.querySelector(".active");
  if(elems !==null) {
    elems.classList.remove("active");
  }
  e.target.className = "active";
}
.flex-nav {
  display: flex;
  flex-direction: column;
  margin-top: 54px;
  background: #333;
  width: 75px;
  height: 657px;
  justify-content: space-around;
  align-items: stretch;
  line-height: 23px;
}

.flex-nav a{
  text-decoration: none;
  color: white;
  flex-wrap: wrap;
  text-align: center;
  margin: 5px;
  border: 1px solid transparent;
}

.flex-nav a.active {
  background: #9999ff;
}
.flex-nav a:hover:not(.active) {
 background: #555;
 border: 1px solid rgba(255, 51, 153,1);
}
  <div class="flex-nav">
     <a href="#" style="order:3">2k</a>
     <a href="#" style="order:2">4k</a>
     <a href="#" style="order:4">1080p</a>
     <a href="#" style="order:1">8k</a>
   </div>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can avoid that behaviour by letting the flex items grow so that there is no space between them: Add these settings to .flex-nav a

flex-grow: 1;
display: flex;
justify-content: center;
align-items: center;

(The first is for the growing, the others are for centering the text inside them)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda