Center an element in Bootstrap 4 Navbar

前端 未结 9 1290
甜味超标
甜味超标 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:58

    from the docs

    Navbars may contain bits of text with the help of .navbar-text. This class adjusts vertical alignment and horizontal spacing for strings of text.

    i applied the .navbar-text class to my <li> element, so the result is

    <li class="nav-item navbar-text">
    

    this centers the links vertically with respect to my navbar-brand img

    0 讨论(0)
  • 2020-11-22 14:59

    I had a similar problem; the anchor text in my Bootstrap4 navbar wasn't centered. Simply added text-center in the anchor's class.

    0 讨论(0)
  • 2020-11-22 15:08

    make new style

    .container {
        position: relative;
    }
    .center-nav {
        position: absolute;
        left: 0;
        right: 0;
        margin: 0 auto;
        width: auto;
        max-width: 200px;
        text-align: center;
    }
    .center-nav li{
      text-align: center;
      width:100%;
    }
    

    Replace website name UL with below

    <ul class="nav navbar-nav center-nav">
            <li class="nav-item"><a class="nav-link" href="#">Website Name</a></li>
     </ul>
    

    Hope this helps..

    0 讨论(0)
提交回复
热议问题