Correct way to center logo and navigation I'm new to CSS and HTML and while I've achieved a centering of the logo and navigation links, it feels wrong.  I'm developing a site for a small non-profit for a side project.  I have a logo next to a few navigation links.  I put the logo and navigation links in a list.

Could someone take a look at this and tell me if my CSS is correct?  I just think that there's something off.  Or that I'm duplicating CSS code.

Here's my JSFiddle to show what I've done.

HTML:

&lt;body&gt;
&lt;nav id="top_nav"&gt;
    &lt;ul id="nav_links"&gt;
        &lt;li&gt;
            &lt;a href="#"&gt;
                &lt;img id="nav_logo" src="logo.png"/&gt;
            &lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a id="nav_whoweare" class="nav_links_border" href="#"&gt;WHO WE ARE&lt;/a&gt;&lt;/li&gt;
        &lt;li &gt;&lt;a id="nav_whatwedo" class="nav_links_border" href="#"&gt;WHAT WE DO&lt;/a&gt;&lt;/li&gt;
        &lt;li &gt;&lt;a id="nav_explore" class="nav_links_border" href="#"&gt;EXPLORE&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a id="nav_donate" href="#"&gt;DONATE&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/nav&gt;

&lt;nav id="bottom_nav"&gt;

&lt;/nav&gt;




CSS:

#top_nav {
    text-align: center;
    width: 100%;
}

#nav_logo {
    /*display: inline-block;*/
    width: 142px;
    height: 159px;
    padding-right: 20px;
    text-decoration: none;
}

#nav_links li a {
    padding: 15px 20px;
    text-decoration: none;
    font-family: Arial;
    font-size: 24px;
    color: #000;
}

/* When window is resized, doesn't wrap menu*/
#nav_links { 
    display: inline-block;
    padding: 0 0 30px 0; 
    list-style:none;
    text-align:left;
    white-space: nowrap;
}

#nav_links li {
    vertical-align: text-top;
    display: inline-block;
    float: none;
    margin: 0 -3px 0 0;

}
/* ------------------------------------*/

a.nav_links_border {
    border-right: 1px solid #f37f43;
}

#nav_links li a:hover {
    text-decoration: underline;
}

#nav_links &gt; img:hover {
    text-decoration: none;
}

#bottom_nav {
    clear: both;
}
There is no real "correct" way to go about it; it all depends on how you want it to look. I can't quite speak to that, only the code you posted, and how it fares.

Anyway: Review.

General cleanliness

You should clean up your code (preferably before posting it, since many the following things should be fairly obvious). You've got a bunch of CSS that doesn't do anything:


There's a line that's just commented out: Remove it.
The #nav_links &gt; img:hover doesn't affect anything. There's no img element immediately descendent from #nav_links
The #bottom_nav style (and indeed the entire element!) is pointless. It seems only to exist to clear any floats. But there are no floats. Similarly, the #nav_links li style has a float: none declaration which does nothing.
You can skip every single link ID (e.g. nav_whoweare); you're not using them. If you find yourself needing them, then add them. But not before.
You don't need width: 100% on the nav element. It's a block element, so it'll do that automatically.
You don't need display: inline-block on the ul element.


I'd also advice you to use a more logical order for you CSS rules. Right now it's haphazard:

#nav_links li a
#nav_links            &lt;&lt; high-level
#nav_links li
#nav_links li a:hover &lt;&lt; low-level


but it would make more sense to mirror the structure of the markup (and just the complexity of the CSS selectors):

#nav_links            &lt;&lt; high-level
#nav_links li
#nav_links li a
#nav_links li a:hover &lt;&lt; low-level


Class names and IDs

"It should be as simple as possible, but no simpler". In other words, only add stuff when there would otherwise be ambiguity.

For instance, there no reason to give the #nav_links list an ID. It's the only &lt;ul&gt; element inside #top_nav, so you can unambiguously reference it as simply #top_nav ul. Or, if you get rid of the bottom_nav element since it's not doing anything, you're left with simply nav ul. (You might want a bottom nav later, but cross that bridge when you come to it; not now).

Furthermore, don't use classes like nav_links_border. It's given that it's a navigation link, because it's inside the &lt;nav&gt; element, and it's given that it's a link because it's an &lt;a&gt; element. So you CSS rule should target nav a rather than an overly specific class like a.nav_links_border.

What you're left with is just border, but that's not terribly descriptive. Looking at it overall, though, it's also obvious that all the links - with 1 exception - have a border. So, really, you'll want a way to treat the exception differently, rather than add a class to everything else.

I'd suggest giving the &lt;li&gt; containing the logo an ID - simply call it logo. This lets you do two things:


You can style all the list items the same basic way, and only do something different for #logo
You can get rid of the ID on the &lt;img&gt; element, since you can instead reference it as #logo img




I get this:

&lt;nav&gt;
    &lt;ul&gt;
        &lt;li id="logo"&gt;
            &lt;a href="#"&gt;&lt;img src="logo.png"/&gt;&lt;/a&gt;
        &lt;/li&gt;

        &lt;li&gt;&lt;a href="#"&gt;WHO WE ARE&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="#"&gt;WHAT WE DO&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="#"&gt;EXPLORE&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="#"&gt;DONATE&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/nav&gt;


And this:

nav {
    text-align: center;
}

nav ul {
    padding: 0 0 30px 0;
    list-style:none;
    text-align:left;
    white-space: nowrap;
}

nav li {
    vertical-align: text-top;
    display: inline-block;
    margin: 0 -3px 0 0;
}

nav a {
    padding: 15px 20px;
    text-decoration: none;
    font-family: Arial;
    font-size: 24px;
    color: #000;
    border-right: 1px solid #f37f43;
}

nav a:hover {
    text-decoration: underline;
}

#logo a {
    border: none;
}

#logo a:hover {
    text-decoration: none;
}

#logo img {
    width: 142px;
    height: 159px;
    padding-right: 20px;
}


Here's a jsfiddle - should look the same (apart from less margin, but that's because I remove the &lt;body&gt; tag from your code; jsfiddle add that itself; you shouldn't do it yourself)