Bootstrap 4将导航栏项目向右对齐

在Bootstrap 4中,通过使用新的Flexbox工具或navbar utilities,可以将导航栏项目右对齐。例如,可以使用`mr-auto`类在左侧创建自动右间距,或者使用`ml-auto`类将项目推到右侧。文章还提供了不同场景下的对齐方法,包括按钮始终显示在右侧的情况。
摘要由CSDN通过智能技术生成

本文翻译自:Bootstrap 4 align navbar items to the right

How do I align a navbar item to right? 如何将导航栏项目右对齐?

I want to have the login and register to the right. 我要登录并在右边注册。 But everything I try does not seem to work. 但是我尝试的所有方法似乎都无法正常工作。

导航栏的图片

This is what I have tried so far: 到目前为止,这是我尝试过的:

  • <div> around the <ul> with the atribute: style="float: right" <div>周围, <ul>带有属性: style="float: right"
  • <div> around the <ul> with the atribute: style="text-align: right" <div><ul> <div>周围,​​带有属性: style="text-align: right"
  • tried those two things on the <li> tags <li>标记上尝试了这两件事
  • tried all those things again with !important added to the end 再次尝试所有这些事情,最后添加!important
  • changed nav-item to nav-right in the <li> <li> nav-right nav-item更改为nav-right
  • added a pull-sm-right class to the <li> <li>添加了pull-sm-right
  • added a align-content-end class to the <li> <li>添加了align-content-end

This is my code: 这是我的代码:

<div id="app" class="container">
  <nav class="navbar navbar-toggleable-md navbar-light bg-faded">
    <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <a class="navbar-brand" href="#">Navbar</a>
    <ul class="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&#
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值