Search code examples
htmltwitter-bootstrapcssvertical-alignment

Bootstrap navbar - align button vertically


I'm trying to align a button inside a nav but I can't figure out how to do it. I placed a logo with the height of 50px and aligned other nav items vertically with the line-height property of 50 px. Right now it looks like this:

enter image description here

When I add a line height to the button as well, the border gets streched out.

Here is my HTML:

<nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">
                    <img alt="Dolm IT" src="img/logo.svg" height="50px">
                </a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">


                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#">services</a></li>
                    <li><a href="#">showcase</a></li>
                    <li><a href="#">our team</a></li>
                    <button type="button" class="btn btn-default navbar-btn">get in touch</button>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>

And here's my CSS:

  /*nav*/

    .navbar {
        background-color: transparent;
        border: 0;
    }

    .navbar-default .navbar-nav > li > a {
        color: #01787e;
        font-family: 'Akrobat-ExtraBold';
        font-size: 1rem;
        text-transform: uppercase;
        letter-spacing: 2px;
        margin-right: 50px;
    }

    .navbar-nav li a {
        line-height: 50px;
    }


    /*buttons*/

    .btn-default {
        color: #01787e;
        font-family: 'Akrobat-ExtraBold';
        font-size: 1rem;
        text-transform: uppercase;
        letter-spacing: 2px;
    }

    .btn {
        border: 2px solid #01787e;
        border-radius: 5px;
        padding: 7px 30px;
    }
    }

You can see the issue here. Thank you for your help.


Solution

  • Give your button.navbar-btn class a margin-top of 25px and you are good to go.

    button.navbar-btn{
          margin-top:25px
        } 
    

    Check fiddle: https://jsfiddle.net/4ku2jhm4/1/