Search code examples
htmlcsscenternavbarnav

Centered navbar with left logo


I'm trying to have a centered navbar, with a logo floated to the left.

Here's a good example: http://www.bootply.com/98314

I want something similar to that example, but to instead swap the left-floated items with the Brand. I will keep the right-floated items there.

I currently have this: http://www.bootply.com/p6XOQQFZQT (don't worry about the not vertically aligned text)

As you can see, if you remove the floated-left element, the navbar centers, meaning that with the floated-left element included, the navbar is not truly centered on the page.

I think I need to have the navigation elements' position absolute so that they stick in the middle, but each time I do this it just removes the entire navbar background and you barely see the text.

I appreciate any and all help!


Solution

  • DEMO: http://jsfiddle.net/6qcrevxe/

    header {
        background: #333;
        width: 100%;
    }
    .global-nav {
        font-size: 13px;
        text-align: center;
        list-style-type: none;
        background-color: #205081;
        line-height: 40px;
        border-bottom: 1px solid #235990;
        position: relative;
    }
    .global-nav ul {
        padding: 10px 0;
        margin: 0;
    }
    .global-nav li {
        display: inline-block;
    }
    .nav-link a {
        padding: 13px;
        color: #fff;
        text-decoration: none;
    }
    .nav-link:hover {
        background-color: #235990;
        color: #fff;
    }
    .nav-left {
        position: absolute;
        left: 10px;
        top: 10px;
    }