image does vertical center in div

Discussion in 'jQuery' started by piropeator, Aug 10, 2016.

  1. #1
    Hi.
    I am having use bootstrap. And I have this code:
    <nav class="navbar navbar-default">
      <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">
            <img alt="Brand" src="images/logo.png">
          </a>
        </div>
      </div>
    </nav>
    HTML:
    This is a bootstrap examble http://getbootstrap.com/components/#navbar-brand-image
    In the example, the image is centered vertically in navbar.
    But, when I use this code my image is does not centered vertically.
    Can somebody help me.
    there any special considerations for the image?
     
    piropeator, Aug 10, 2016 IP
  2. bmills

    bmills Peon

    Messages:
    6
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    3
    #2
    In the example the brand image is definitely on the left...unless you're looking at something else. Anyways try this:
    .navbar {
    position: relative;
    }
    .navbar-brand {
    position: absolute;
    left:50%;
    margin-left:-50px!important;/* 50% of your logo width */
    display: block;
    }
     
    bmills, Aug 10, 2016 IP
  3. swissmistery

    swissmistery Greenhorn

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    20
    #3

    You need to use a custom class. Bootstrap doesn't have vertical-center class.

    .vcenter {
        display: inline-block;
        vertical-align: middle;
        float: none;
    }
    Code (CSS):
    Source: http://stackoverflow.com/questions/20547819/vertical-align-with-bootstrap-3
     
    swissmistery, Aug 11, 2016 IP