简体   繁体   中英

Center li elements with ul

I have li elements in a nav menu, and I want to center the elements in the ul . I know this question has been asked many times, but I have tried almost everything and still cannot get it to work the way I would like. Here's the relevant portion of the code:

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
      </button>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav"id="nav">
        <li class="active"><a href="HomePage.html" id="homepageLink">Home</a></li>
        <li><a href="Login.html" id="loginLink">Login</a></li>
        <li><a href="Registration.html" id="registrationLink">Registration</a></li>
      </ul>
    </div>
  </div>
</nav>

Here's the HTML for the whole homepage

add this css code

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

.navbar .navbar-collapse {
  text-align: center;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM