Reputation: 21
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
Reputation: 372
just put text align center to nav
nav {
text-align: center;
}
Upvotes: 1
Reputation: 5217
nav{
text-align: center;
background: green;
}
ul{
padding: 0;
}
Upvotes: 1
Reputation: 42352
You can do two things to center the ul
:
Add text-align: center
to the nav
to center the ul
inside it.
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