Bootstrap 4导航栏,有2行我创建了一个带有Bootstrap 4 alpha 6的导航栏,左侧有一个大品牌/图标,还有2个navbar-nav,带有图标右侧的链接。一个导航有链接,另一个导航有图标。除了一件事,它正如我想要的那样工作。我希望2个导航栏出现在图标右侧的2个单独的行中。像这样:------------------------------------------------------ link link link link brand-icon ------------------------------------------- icon icon icon------------------------------------------------------移动版仍将像现在一样垂直显示链接。我用flexbox尝试了几种不同的东西,但无法让它工作。这是我的代码:<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse"> <div class="container"> <button class="navbar-toggler navbar-toggler-right align-self-center mt-3" type="button" data-toggle="collapse" data-target="#navbarCollapse"> <span class="navbar-toggler-icon"></span> </button> <h1 class="py-2 ml-lg-2 mx-3"><a href="#"><i class="fa fa-envelope-open-o fa-lg" aria-hidden="true"></i></a></h1> <div class="collapse navbar-collapse ml-lg-0 ml-3" id="navbarCollapse"> <ul class="navbar-nav"> <li class="nav-item active"> <a class="nav-link" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Product</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Shop</a> </li> <li class="nav-item"> <a class="nav-link" href="#">About</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Events</a> </li> </ul> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link pr-3" href="#"><i class="fa fa-facebook"></i></a> </li> <li class="nav-item"> <a class="nav-link pr-3" href="#"><i class="fa fa-instagram"></i></a> </li> <li class="nav-item">
2 回答
慕田峪4524236
TA贡献1875条经验 获得超5个赞
您可以使用flex-column
flexbox实用程序类在图标旁边垂直堆叠2个导航。这将flex-direction: column
在navbar-collapse
div中,它的子元素垂直堆叠。
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse"> <div class="container"> <button class="navbar-toggler navbar-toggler-right align-self-center mt-3" type="button" data-toggle="collapse" data-target="#navbarCollapse"> <span class="navbar-toggler-icon"></span> </button> <h1 class="py-2 ml-lg-2 mx-3"><a href="#"><i class="fa fa-envelope-o fa-lg mt-2" aria-hidden="true"></i></a></h1> <div class="collapse navbar-collapse flex-column ml-lg-0 ml-3" id="navbarCollapse"> <ul class="navbar-nav"> <li class="nav-item active"> <a class="nav-link" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Product</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Shop</a> </li> <li class="nav-item"> <a class="nav-link" href="#">About</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Events</a> </li> </ul> <ul class="navbar-nav flex-row mb-2"> <li class="nav-item"> <a class="nav-link py-1 pr-3" href="#"><i class="fa fa-facebook"></i></a> </li> <li class="nav-item"> <a class="nav-link py-1 pr-3" href="#"><i class="fa fa-instagram"></i></a> </li> <li class="nav-item"> <a class="nav-link py-1 pr-3" href="#"><i class="fa fa-twitter"></i></a> </li> </ul> </div> </div></nav>
这是另一个带有2行和右对齐搜索形式的变体:
<nav class="navbar navbar-toggleable-md navbar-light bg-faded"> <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarCollapse"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand my-auto" href="#">Brand</a> <div class="collapse navbar-collapse flex-md-column" id="navbarCollapse"> <ul class="navbar-nav ml-auto small"> <li class="nav-item active"> <a class="nav-link" href="#">Shop</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Products</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Team</a> </li> <li class="nav-item"> <a class="nav-link" href="#">About</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Events</a> </li> </ul> <form class="form-inline ml-auto"> ... </form> </div></nav>
开满天机
TA贡献1786条经验 获得超13个赞
对于我来说,“2行右对齐的变化”没有正确对齐Safari中的行。我将无序列表放在带有flex-column
和ml-auto
类的新div中。
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse"> <div class="container"> <button class="navbar-toggler navbar-toggler-right align-self-center mt-3" type="button" data-toggle="collapse" data-target="#navbarCollapse"> <span class="navbar-toggler-icon"></span> </button> <h1 class="py-2 ml-lg-2 mx-3"><a href="#"><i class="fa fa-envelope-open-o fa-lg" aria-hidden="true"></i></a></h1> <div class="collapse navbar-collapse ml-lg-0 ml-3" id="navbarCollapse"> <div class="flex-column ml-auto"> <ul class="navbar-nav"> <li class="nav-item active"> <a class="nav-link" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Product</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Shop</a> </li> <li class="nav-item"> <a class="nav-link" href="#">About</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Events</a> </li> </ul> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link pr-3" href="#"><i class="fa fa-facebook"></i></a> </li> <li class="nav-item"> <a class="nav-link pr-3" href="#"><i class="fa fa-instagram"></i></a> </li> <li class="nav-item"> <a class="nav-link pr-3" href="#"><i class="fa fa-twitter"></i></a> </li> </ul> </div> </div> </div> </nav>
- 2 回答
- 0 关注
- 951 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消