Center an element in Bootstrap 4 Navbar

前端 未结 9 1291
甜味超标
甜味超标 2020-11-22 14:26

No matter what I try, I can\'t center something in Bootstrap navbar, any solutions for it?

I\'ve tried adding a div, using margin:0 auto; or marg

9条回答
  •  清酒与你
    2020-11-22 14:55

    In Bootstrap 4, there is a new utility known as .mx-auto. You just need to specify the width of the centered element.

    Ref: http://v4-alpha.getbootstrap.com/utilities/spacing/#horizontal-centering

    Diffferent from Bass Jobsen's answer, which is a relative center to the elements on both ends, the following example is absolute centered.

    Here's the HTML:

    
    

    And CSS:

    .navbar-logo {
      width: 90px;
    }
    

提交回复
热议问题