Home  >  Article  >  Web Front-end  >  How to center the bootstrap navigation bar

How to center the bootstrap navigation bar

(*-*)浩
(*-*)浩Original
2019-07-17 09:43:186458browse

When I used Bootstrap to practice imitating a website today, I found that the menu in the navigation bar of the target website is centered. However, Bootstrap does not seem to have a centered style for the navigation menu. It took me a long time and many tests to finally find a solution.

How to center the bootstrap navigation bar

The first method: add the following styles to div and ul: (recommended learning: Bootstrap video tutorial )

<div class="navbar-collapse collapse" style="text-align: center;">
  <ul class="nav navbar-nav" style="display: inline-block;float: none;">
    <li class="">
        <a href="#">首页</a>
    </li>
    <li class="">
        <a href="#">加入我们</a>
    </li>
    <li class="">
        <a href="#">联系我们</a>
    </li>
  </ul>
</div>

Second method:

<div class="navbar-collapse collapse">
  <ul class="nav navbar-nav">
    <li class="">
        <a href="#">首页</a>
    </li>
    <li class="">
        <a href="#">加入我们</a>
    </li>
    <li class="">
        <a href="#">联系我们</a>
    </li>
  </ul>
</div>

Add the following style:

.navbar-nav {
  float: none;
  text-align:center;
}
ul.nav.navbar-nav  li {
    float:none;
    display: inline-block;
    margin: 0em;
}

More Bootstrap related technical articles, Please visit the Bootstrap Tutorial column to learn!

The above is the detailed content of How to center the bootstrap navigation bar. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn