Bootstrap 3 : Vertically Center Navigation Links when Logo Increasing The Height of Navbar

后端 未结 6 764
说谎
说谎 2020-12-07 20:32

I\'m new to the bootstrap framework.

Logo Increasing Height of NavBar:

In my navigation bar, I have inserted a logo that has a height of 50p

相关标签:
6条回答
  • 2020-12-07 21:14

    Use the Bootstrap Customizer to generate a version of Bootstrap that has a taller navbar. The value you want to change is @navbar-height in the Navbar section.

    Inspect your current implementation to see how tall your navbar is with the 50px brand image, and use that calculated height in the Customizer.

    0 讨论(0)
  • 2020-12-07 21:14

    I found that you don't necessarily need the text vertically centred, it also looks good near the bottom of the row, it's only when it's at the top (or above centre?) that it looks wrong. So I went with this to push the links to the bottom of the row:

    .navbar-brand {
        min-height: 80px;
    }
    
    @media (min-width: 768px) {
        #navbar-collapse {
            position: absolute;
            bottom: 0px;
            left: 250px;
        }
    }
    

    My brand image is SVG and I used height: 50px; width: auto which makes it about 216px wide. It spilled out of its container vertically so I added the min-height: 80px; to make room for it plus bootstrap's 15px margins. Then I tweaked the navbar-collapse's left setting until it looked right.

    0 讨论(0)
  • 2020-12-07 21:14

    I actually ended up with something like this to allow for the navbar collapse.

    @media (min-width: 768px) { //set this to wherever the navbar collapse executes
      .navbar-nav > li > a{
        line-height: 7em; //set this height to the height of the logo.
      }
    }
    
    0 讨论(0)
  • 2020-12-07 21:18

    add this to your stylesheet. line-height should match the height of your logo

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

    Check out the fiddle at: http://jsfiddle.net/nD4tW/

    0 讨论(0)
  • 2020-12-07 21:28

    Bootstrap sets the height of the navbar automatically to 50px. The padding above and below links is set to 15px. I think that bootstrap is adding padding to your logo.

    You can either remove some of the padding above and below your logo or you can add more padding above and below links.

    Adding more padding should look something like this:

    nav.navbar-inverse>li>a {
     padding-top: 25px;
     padding-bottom: 25px;
    }
    
    0 讨论(0)
  • 2020-12-07 21:34

    Matt's answer is fine, but just to avoid this to propagate to other elements inside the navbar (like when you also have a dropdown), use

    .navbar-nav > li > a {
       line-height: 50px;
    }
    
    0 讨论(0)
提交回复
热议问题