无法将无序列表与“ flex-column”对齐

时间:2019-12-29 04:48:26

标签: html css bootstrap-4

我正在创建一个垂直导航-顶部ul列表将与顶部对齐,而另一个将与底部对齐。现在,我的导航看起来像两列,而不是一长串项目:https://www.dropbox.com/s/3pmwuih7xij51fj/Screen%20Shot%202019-12-28%20at%2010.41.34%20PM.png?dl=0

以下是photoshop的一项快速工作,以显示我的期望(所有菜单项都在一栏中): enter image description here

我尝试添加w-100,但是我无法使它们与一个col对齐。我如何在两者之间建立一个休息?

<div class="container-fluid">
  <div class="row">
    <div class="col-1" style="background-color: aliceblue; height: 600px;">
      <nav class="navbar navbar-expand-md flex-column p-0"> <a class="navbar-brand" href="#">logo</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button>
        <div class="collapse navbar-collapse" id="navbarsExampleDefault">
          <ul class="navbar-nav flex-column">
            <li class="nav-item active"> <a class="nav-link" href="#">Help <span class="sr-only">(current)</span></a> </li>
            <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
            <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
            <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
          </ul>
          <ul class="navbar-nav flex-column">
            <li class="nav-item active"> <a class="nav-link" href="#">Help <span class="sr-only">(current)</span></a> </li>
            <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
            <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
            <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
          </ul>
        </div>
      </nav>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:1)

您应将 flex-column 添加到div #navbarsExampleDefault 中,并在2个 < em> ul ,您可以添加 hr 以将它们分开,然后对其进行样式设置。

<div class="container-fluid">
<div class="row">
    <div class="col-1" style="background-color: aliceblue; height: 600px;">
        <nav class="navbar navbar-expand-md flex-column p-0"> <a class="navbar-brand" href="#">logo</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse"
                data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false"
                aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button>
            <div class="collapse navbar-collapse flex-column" id="navbarsExampleDefault">
                <ul class="navbar-nav flex-column">
                    <li class="nav-item active"> 
                        <a class="nav-link" href="#">
                            Help <span class="sr-only">(current)</span>
                        </a> 
                    </li>
                    <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
                    <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
                    <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
                </ul>
                <hr>
                <ul class="navbar-nav flex-column">
                    <li class="nav-item active"> 
                        <a class="nav-link" href="#">
                            Help <span class="sr-only">(current)</span>
                        </a> 
                    </li>
                    <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
                    <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
                    <li class="nav-item"> <a class="nav-link" href="#">Help</a> </li>
                </ul>
            </div>
        </nav>
    </div>
</div>