Question

I need to center the nav in this website ( http://beautra.weebly.com/ ), any ideas? Here's the code, I tried playing with the inspect element tool but I couldn't work it out. The code seems simple enough to work out but I don't know how to work with jsfiddle. Any help with that too would be appreciated. Thanks,

/* Navigation --------------------------------------------------------------------------------*/

#topnav {
    clear: both;
    text-align:center;
    background: url(nav-left.png) no-repeat;
    padding-left: 8px;
    width: 971px;
}

#nav-right {
    background: url(nav-right.png) right top no-repeat;
    padding-right: 10px;
}

#nav-inner {
    background: url(nav-inner.png) repeat-x;
    padding: 2px 5px 3px;
}

#topnav ul {
    list-style: none;
    float: none;
    background: url(nav-sep.jpg) no-repeat left center;
}

#topnav ul li {
    list-style: none;
    float: left;
    background: url(nav-sep.jpg) no-repeat right center;
    padding-right: 2px;
}

#topnav a {
    float: left;
    text-align:center;
    display: block;
    color: #989899;
    text-decoration: none;
    padding: 19px 38px;
    border: 0;
    outline: 0;
    list-style-type: none;
    font-size: .9em;
}

#topnav li#active a,
#topnav a:hover {
    transition: 0.5s; 
    -moz-transition: 0.5s; 
    -webkit-transition: 0.5s; 
    -o-transition: 0.5s; 
    color: #ed53ae;
    background: #090909 url(nav-active.png);
    border: 0;
}
Was it helpful?

Solution

I'd suggest making the child ul element inline-block.

#nav-inner > ul {
    display: inline-block;
}

And then adding text-align:center to the parent element, #nav-inner.

#nav-inner {
    text-align: center;
    background: url(theme/nav-inner.png?486154) repeat-x;
    padding: 2px 5px 3px;
}

This will ensure that the menu is centered regardless of its dimensions - good for dynamic content (i.e., you don't have to set a fixed width and use margin:0 auto..).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top