Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center a navigation bar with CSS or HTML?

I am having difficulty with centering the navigation bar on this page.

I tried nav { margin: 0 auto; } and a bunch of other ways, but I still can't center it.

like image 848
tokyowp Avatar asked May 13 '11 17:05

tokyowp


People also ask

How do I center my navigation bar in CSS?

Make your div container the 100% width. and set the text-align: element to center in the div container. Then in your <ul> set that class to have 3 particular elements: text-align:center; position: relative; and display: inline-block; that should center it.

How do you center something in HTML CSS?

To just center the text inside an element, use text-align: center; This text is centered.

Should you center in HTML or CSS?

It is always better to separate the "code" (HTML) and the styles (CSS), so in any case, CSS is the way to go. Show activity on this post. To be short, just don't use center tag.


1 Answers

#nav ul {
    display: inline-block;
    list-style-type: none;
}

It should work, I tested it in your site.

enter image description here

like image 90
morgar Avatar answered Sep 20 '22 22:09

morgar