为了账号安全,请及时绑定邮箱和手机立即绑定

如何将导航项与导航栏中的右侧对齐?

如何将导航项与导航栏中的右侧对齐?

Go
繁星点点滴滴 2023-08-21 16:17:57
如何将导航项对齐到特定位置?我希望我的品牌名称位于导航栏的左侧,登录按钮位于导航栏的右端,我是引导程序新手,请帮助我解决这个问题。.navbar-brand {  font-weight: bold;}<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"><div class="container">  <ul class="nav">    <li class="nav-item">      <a class="nav-link navbar-brand active" href="#">NotePro</a>    </li>    <li class="nav-item ">      <a class="nav-link" href="#">LogIn</a>    </li>  </ul></div>
查看完整描述

3 回答

?
狐的传说

TA贡献1804条经验 获得超3个赞

您可以对元素使用 Bootstrap 类 d-flex 和 justify-content- Between ul

.navbar-brand {

  font-weight: bold;

}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<div class="container">

  <ul class="nav d-flex justify-content-between">

    <li class="nav-item">

      <a class="nav-link navbar-brand active" href="#">NotePro</a>

    </li>

    <li class="nav-item ">

      <a class="nav-link" href="#">LogIn</a>

    </li>

  </ul>

</div>



查看完整回答
反对 回复 2023-08-21
?
慕的地8271018

TA贡献1796条经验 获得超4个赞

将此代码添加到container


.container {

  display: flex;

  justify-content: space-between;

}

并将品牌移到ul标签之外


.navbar-brand {

  font-weight: bold;

}


.container {

  display: flex;

  justify-content: space-between;

}

<!DOCTYPE html>

<html dir="ltr">


<head>

  <meta charset="utf-8">

  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

  <link rel="stylesheet" href="new.css">

  <title>NotePro</title>

</head>


<body>

  <div class="container">

    <a class="nav-link navbar-brand active" href="#">NotePro</a>

    <ul class="nav">

      <li class="nav-item ">

        <a class="nav-link" href="#">Home</a>

      </li>

      <li class="nav-item ">

        <a class="nav-link" href="#">about us</a>

      </li>

      <li class="nav-item ">

        <a class="nav-link" href="#">LogIn</a>

      </li>

    </ul>

  </div>

</body>


</html>


查看完整回答
反对 回复 2023-08-21
?
holdtom

TA贡献1805条经验 获得超10个赞

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>



<!--here is your code below-->


<nav class="navbar navbar-expand-lg navbar-light bg-light">

        <a class="navbar-brand" href="#">Navbar</a>

        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">

          <span class="navbar-toggler-icon"></span>

        </button>


        <div class="collapse navbar-collapse" id="navbarSupportedContent">

            <ul class="navbar-nav ml-auto">

                <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="#">Link</a>

                </li>

                <li class="nav-item dropdown">

                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">

                Dropdown

              </a>

                    <div class="dropdown-menu" aria-labelledby="navbarDropdown">

                        <a class="dropdown-item" href="#">Action</a>

                        <a class="dropdown-item" href="#">Another action</a>

                        <div class="dropdown-divider"></div>

                        <a class="dropdown-item" href="#">Something else here</a>

                    </div>

                </li>

                <li class="nav-item">

                    <a class="nav-link disabled" href="#">Disabled</a>

                </li>

            </ul>

            <form class="form-inline my-2 my-lg-0">

                <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">

                <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>

            </form>

        </div>

    </nav>

在您的 UL 上使用 ml-auto



查看完整回答
反对 回复 2023-08-21
  • 3 回答
  • 0 关注
  • 163 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信