html - 在 Bootstrap Nav 中居中一项

标签 html css twitter-bootstrap

我试图在我的 Bootstrap 导航中将特定链接居中。

我的代码:

<nav class="navbar navbar-default user_info_bar" role="navigation">
  <div class="collapse navbar-collapse">

    <ul class="nav navbar-nav">
      <li>
        <p class="navbar-text"><%= @user.screens.count %> Screenshots</p>
      </li>
      <li>
        <p class="navbar-text"><%= @user.points %> Points</p>
      </li>
    </ul>

    <ul class="nav navbar-nav"> <!-- This must be in the middle -->
      <li class="user_follow">
        <%= link_to "Follow", follow_user_path %>
      </li>
    </ul>

    <ul class="nav navbar-nav navbar-right">
      <li>
        <p class="navbar-text"><%= @user.follow_count %> Following</p>
      </li>

      <li>
        <p class="navbar-text"><%= @user.followers.count %> Followers</p>
      </li>
    </ul>

  </div>
</nav>

http://bootply.com/107875

现在我在左边和右边有 2 个按钮。我正在尝试将“关注”按钮准确地置于中心。

最佳答案

<ul class="nav navbar-nav centerContainer"> <!-- This must be in the middle -->
  <li class="user_follow">  
     <%= link_to "Follow", follow_user_path %>
  </li>
</ul>

CSS

.centerContainer {
  position: absolute;
  left: 50%;
}

http://bootply.com/107882

关于html - 在 Bootstrap Nav 中居中一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21296461/

相关文章:

css - 将参数传递给 css 动画

javascript - Jquery - 通过单击 li 设置其他 li 元素的样式

jquery - CSS 替代此 CSS-jQuery 代码?

android - 适用于 Android 的 RSS 阅读器的 IBM 教程无法正常工作

html - 获取 :first-letter to ignore image?

css - Bootstrap 3 导航栏图像

html - 显示 flex 收缩 div 元素

jquery - 将单列文本输入重新排列为多列

css - 2 个内联图像 - 1 个居中和 1 个使用 Bootstrap

html - Bootstrap 包含同一行的五个图像