Centering Navbar in Agency- Bootstrap 4 Theme

后端 未结 2 1135
日久生厌
日久生厌 2021-01-21 14:18

I was just wondering if anyone could help me with a problem I have been stuck on for a while. What I am wanting to accomplish is centring the menu at the top of the page (so tha

相关标签:
2条回答
  • 2021-01-21 14:34

    You can also do it without using "Flex"

    .navbar-collapse{
      text-align: center;
    }
    
    .navbar-nav {
        float: none;
        margin: 0 auto;
        display: inline-block;
    }
    

    Here the Fiddle

    0 讨论(0)
  • 2021-01-21 14:57

    You will need to override some Bootstrap styles. You can use css3 flexbox to center align navigation items.

    Following Bootstrap styles are being applied on .navbar:

    @media (min-width: 768px)
      .navbar-nav {
        float: left;
      }
    }
    

    Override them in your custom style sheet.

    @media (min-width: 768px)
      .navbar-nav {
        float: none;
        display: flex;
        justify-content: center;
      }
    }
    

    Or if you don't wants to use flexbox then you can use following css:

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

    Update Fiddle:

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