Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS / HTML Navigation and Logo on same line

I can't figure out how to put them on the same line.

http://codepen.io/anon/pen/dovZdQ

<body>
    <div class="navigation-bar">
        <div id="navigation-container">
            <img src="logo.png"> 
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">Projects</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Services</a></li>
                <li><a href="#">Get in Touch</a></li>
            </ul>
        </div>
    </div>
</body>
like image 981
Денислав Ангелов Avatar asked Jun 03 '15 15:06

Денислав Ангелов


People also ask

How do I align the navbar and logo on the same line?

I suggest you to use display: flex; for the header tag as well this will help you align the logo and nav-list on the same line.

How do I add a logo to the navigation bar?

We just need to add a div tag with the class as a container and put the navbar-brand(image or logo) inside this div. After that, we just need to add the class mx-auto to the navbar-brand class.

How do I put a logo next to my header in HTML?

Just stick the img tag inside the h1 tag as part of the content.


2 Answers

The <ul> is by default a block element, make it inline-block instead:

.navigation-bar ul {
  padding: 0px;
  margin: 0px;
  text-align: center;
  display:inline-block;
  vertical-align:top;
}

CodePen Demo

like image 137
Jacob Gray Avatar answered Sep 30 '22 14:09

Jacob Gray


Firstly, let's use some semantic HTML.

<nav class="navigation-bar">
    <img class="logo" src="logo.png">
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Projects</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Get in Touch</a></li>
    </ul>
</nav>

In fact, you can even get away with the more minimalist:

<nav class="navigation-bar">
    <img class="logo" src="logo.png">
    <a href="#">Home</a>
    <a href="#">Projects</a>
    <a href="#">About</a>
    <a href="#">Services</a>
    <a href="#">Get in Touch</a>
</nav>

Then add some CSS:

.navigation-bar {
    width: 100%;  /* i'm assuming full width */
    height: 80px; /* change it to desired width */
    background-color: red; /* change to desired color */
}
.logo {
    display: inline-block;
    vertical-align: top;
    width: 50px;
    height: 50px;
    margin-right: 20px;
    margin-top: 15px;    /* if you want it vertically middle of the navbar. */
}
.navigation-bar > a {
    display: inline-block;
    vertical-align: top;
    margin-right: 20px;
    height: 80px;        /* if you want it to take the full height of the bar */
    line-height: 80px;    /* if you want it vertically middle of the navbar */
}

Obviously, the actual margins, heights and line-heights etc. depend on your design.

Other options are to use tables or floats for layout, but these are generally frowned upon.

Last but not least, I hope you get cured of div-itis.

like image 43
light Avatar answered Sep 30 '22 13:09

light