Float nav items to the right in Bootstrap 4?

时光总嘲笑我的痴心妄想 提交于 2019-12-12 04:23:15

问题


How do you push to the right nav items of a Bootstrap 4 navbar? I tried float-*-right but did not work.

  <nav class="navbar navbar-static-top navbar-dark bg-inverse float-*-right">
  <a class="navbar-brand" href="#">Project name</a>
  <ul class="nav navbar-nav">
    <li class="nav-item active">
      <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">About</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Contact</a>
    </li>
  </ul>
</nav>

I need to align the nav items to the right.


回答1:


Add 'float-xs-right' class to the ul

<ul class="nav navbar-nav float-xs-right">

You can remove 'float-*-right' from the containing nav tag since it's not doing anything there

http://www.bootply.com/OnvcimHYD7




回答2:


Update 2018

float-right will no longer work because the Bootstrap 4 Navbar uses flexbox. The auto-margin class (ie:ml-auto) should be used instead.

See: Bootstrap 4 align navbar items to the right



来源:https://stackoverflow.com/questions/41203456/float-nav-items-to-the-right-in-bootstrap-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!