如何在单独的行上安装Brand和Navbar?

时间:2018-04-11 17:11:47

标签: css twitter-bootstrap bootstrap-4 navbar

非常简单,但我对Bootstrap非常业余。

我理解如何使用图像作为品牌和导航项来制作导航栏。没有黑客攻击,有没有一种正确的方法让品牌定位在扩展导航之上?

基本上寻找这个;

EXPANDED
-----------------------------------------
|                 Logo                  |
-----------------------------------------
|         Home   About   Contact        |
-----------------------------------------

COLLAPSED
-----------------
| Logo        ≡ |
-----------------
<nav class="mainNav navbar navbar-expand-md justify-content-center">
    <a class="navbar-brand" href="#">
        <img src="img/logo.png" alt="Logo" height="80px" width="auto">
    </a>
    <ul class="navbar-nav">
        <li class="nav-item">
            <a class="nav-link" href="#">Home</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>

1 个答案:

答案 0 :(得分:3)

使用flex-column使导航栏项目堆叠成2行(行)。

  • 将徽标和组合分组在1个flexbox div(d-flex w-100
  • 中一起切换
  • 使用mx-md-auto(自动边距)将徽标置于更大的宽度上
  • 使用text-centernavbar-nav
  • 中的项目居中

https://www.codeply.com/go/W9HQcd3Pyw

<nav class="mainNav navbar navbar-expand-md navbar-light flex-column">
    <div class="w-100 d-flex">
        <a class="navbar-brand mx-md-auto" href="#">
            <img src="img/logo.png" alt="Logo" height="80px" width="auto">
        </a>
        <button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="navbar-toggler-icon"></span>
        </button>
    </div>
    <div class="collapse navbar-collapse">
        <ul class="navbar-nav text-center">
            <li class="nav-item">
                <a class="nav-link" href="#">Home</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>
    </div>
</nav>

详细了解Bootstrap 4文档中的NavbarUtility类。

相关问题
How to centre navbar logo in Boostrap 4 with nav-links below
Bootstrap 4: Navbar with logo and 2 rows
Bootstrap 4 navbar with 2 rows and inline form