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

71
Views
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 answers
Answer question

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 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!