Center content in responsive bootstrap navbar

后端 未结 11 2172
自闭症患者
自闭症患者 2020-11-22 08:40

I\'m having trouble centering my content in the bootstrap navbar. I\'m using bootstrap 3. I\'ve read many posts, but the CSS or methods used will not work with my code! I\'m

11条回答
  •  猫巷女王i
    2020-11-22 09:00

    I think this is what you are looking for. You need to remove the float: left from the inner nav to center it and make it a inline-block.

    .navbar .navbar-nav {
      display: inline-block;
      float: none;
      vertical-align: top;
    }
    
    .navbar .navbar-collapse {
      text-align: center;
    }
    

    http://jsfiddle.net/bdd9U/2/

    Edit: if you only want this effect to happen when the nav isn't collapsed surround it in the appropriate media query.

    @media (min-width: 768px) {
        .navbar .navbar-nav {
            display: inline-block;
            float: none;
            vertical-align: top;
        }
    
        .navbar .navbar-collapse {
            text-align: center;
        }
    }
    

    http://jsfiddle.net/bdd9U/3/

提交回复
热议问题