Twitter-Bootstrap-2 logo image on top of navbar

前端 未结 5 1310
野性不改
野性不改 2020-12-22 18:12

Can someone suggest how I can place a logo image on the top of the navbar? My markup:

  
     

        
5条回答
  •  北海茫月
    2020-12-22 18:26

    You should remove navbar-fixed-top class otherwise navbar stays fixed on top of page where you want logo.


    If you want to place logo inside navbar:

    Navbar height (set in @navbarHeight LESS variable) is 40px by default. Your logo has to fit inside or you have to make navbar higher first.

    Then use brand class:

    
    

    If your logo is higher than 20px, you have to fix stylesheets as well.

    If you do that in LESS:

    .navbar .brand {
      @elementHeight: 32px;
      padding: ((@navbarHeight - @elementHeight) / 2 - 2) 20px ((@navbarHeight - @elementHeight) / 2 + 2);
    }
    

    @elementHeight should be set to your image height.

    Padding calculation is taken from Twitter Bootstrap LESS - https://github.com/twitter/bootstrap/blob/v2.0.4/less/navbar.less#L51-52

    Alternatively you can calculate padding values yourself and use pure CSS.

    This works for Twitter Bootstrap versions 2.0.x, should work in 2.1 as well, but padding calculation was changed a bit: https://github.com/twitter/bootstrap/blob/v2.1.0/less/navbar.less#L50

提交回复
热议问题