jacob
jacob

Reputation: 21

Can't get navigation bar to center

Have tried a lot of different things but can not figure out why it won't center. Any help would be awesome!

nav {
  font-size: 18px;
}
ul {
  list-style-type: none;
  display: inline-block;
}
li {
  display: inline-block;
}
li a {
  color: #F55F5F;
  padding: 10px 15px;
  text-decoration: none;
  text-align: center;
}
<nav>
  <ul>
    <li><a href="Home.html">Home</a>
    </li>
    <li><a href="Services.html">Services</a>
      <li><a href="About.html">About Us</a>
      </li>
      <li><a href="Contact.html">Contact Us</a>
  </ul>
</nav>

Upvotes: 2

Views: 800

Answers (3)

dheeraj Kumar
dheeraj Kumar

Reputation: 372

just put text align center to nav

 nav {
     text-align: center;
  }

Upvotes: 1

Syam Pillai
Syam Pillai

Reputation: 5217

nav{
  text-align: center;
  background: green;
}
ul{
  padding: 0;
}

Upvotes: 1

kukkuz
kukkuz

Reputation: 42352

You can do two things to center the ul:

  1. Add text-align: center to the nav to center the ul inside it.

  2. Reset the default left padding of ul

See demo below:

nav {
  font-size: 18px;
  text-align: center;
}
ul {
  padding: 0;
  list-style-type: none;
  display: inline-block;
}
li {
  display: inline-block;
}
li a {
  color: #F55F5F;
  padding: 10px 15px;
  text-decoration: none;
  text-align: center;
}
<nav>
  <ul>
    <li><a href="Home.html">Home</a>
    </li>
    <li><a href="Services.html">Services</a>
      <li><a href="About.html">About Us</a>
      </li>
      <li><a href="Contact.html">Contact Us</a>
  </ul>
</nav>

Upvotes: 1

Related Questions