Reputation: 8395
I'm buidling my site and I'm trying to horizontal centering the following code with no luck: http://codepen.io/anon/pen/LZZJrK
If I'm not wrong I must add a css code for nav ul
so I added the following code but it's not working:
nav ul li {
display:block;
text-align:center;
}
Can someone please tell me how can I center the menu so I can have the following output? Thanks in advance.
Upvotes: 0
Views: 74
Reputation: 6904
Add display: table;
and margin: 0 auto;
to your nav
like this:
nav {
display: table;
margin: 0 auto;
}
Upvotes: 2
Reputation: 472
You could do it like this:
nav {
text-align: center;
}
nav ul {
display: inline-block;
}
Because the ul tag is a block level element it will stretch the full width of the parent element
More info: here
Upvotes: 1
Reputation: 18585
I think all you really need is text-align:center
on the parent element of the items/links/buttons
#container{
text-align:center;
}
<div id="container">
<a href="#">One</a>
<a href="#">Two</a>
</div>
Upvotes: 1
Reputation: 16341
float: left
property from nav ul li
and nav li
display:block
to display: inline-block
for li
#nav ul {
text-align:center;
}
CodePen: http://codepen.io/anon/pen/XKKPGO
Upvotes: 1
Reputation: 529
Try with this:
ul{
text-align:center;}
li{
display: inline-block;
float:none;
text-align:center;
}
Upvotes: 1