16

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.

Aruna
  • 11,959
  • 3
  • 28
  • 42
tokyowp
  • 423
  • 3
  • 10
  • 18

7 Answers7

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

It should work, I tested it in your site.

enter image description here

morgar
  • 2,339
  • 17
  • 16
13

Add some CSS:

div#nav{
  text-align: center;
}
div#nav ul{
  display: inline-block;
}
Niclas Sahlin
  • 1,125
  • 9
  • 15
4

If you have your navigation <ul> with class #nav Then you need to put that <ul> item within a div container. 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.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Brandon
  • 1,401
  • 1
  • 16
  • 25
2

Just add :

*{
    margin: 0;
    padding: 0;
}

nav{
    margin: 0 auto;
    text-align: center;
}
executable
  • 3,365
  • 6
  • 24
  • 52
0

The best way to fix it I have looked for the code or trick how to center nav menu and found the real solutions it works for all browsers and for my friends ;)

Here is how I have done:

body {
    margin: 0;
    padding: 0;
}

div maincontainer {
    margin: 0 auto;
    width: ___px;
    text-align: center;
}

ul {
    margin: 0;
    padding: 0;
}

ul li {
    margin-left: auto;
    margin-right: auto;
}

and do not forget to set doctype html5

Mario S
  • 11,715
  • 24
  • 39
  • 47
polas
  • 1
0

You could also use float and inline-block to center your nav like the following:

nav li {
   float: left;
}
nav {
   display: inline-block;
}
camara
  • 1
0

Your nav div is actually centered correctly. But the ul inside is not. Give the ul a specific width and center that as well.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
AlbertVo
  • 772
  • 4
  • 9