Skip to content Skip to sidebar Skip to footer

Centering Items Within Navigation Bar

I've been trying to center the items within the navigation but no such luck. Every single solution turns my navigation bar from this: horizontal navigation bar to this: vertical na

Solution 1:

Just remove the float from the li and make the inline-block

li {    
/* float: left;   */display:inline-block;
}

The first rule of centering is..."Don't use floats"

ul {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
  text-align: center;
}
li {
  display: inline-block;
}
lia {
  display: block;
  color: white;
  text-align: center;
  padding: 10px10px;
  text-decoration: none;
}
lia:hover {
  background-color: #111;
}
<ul><li><aclass="active"href="#home">Home</a></li><li><ahref="#news">News</a></li><li><ahref="#contact">Contact</a></li><li><ahref="#about">About</a></li></ul>

Solution 2:

I removed your css on li tag with float and changed it to display and width:

li {
display: -webkit-inline-box;
width: 60px;

}

https://i.stack.imgur.com/LbYd4.png`

I hope this helped you @C. Lagos

Post a Comment for "Centering Items Within Navigation Bar"