如何通过下面的导航链接将Boostrap

如何通过下面的导航链接将Boostrap

本文介绍了如何通过下面的导航链接将Boostrap 4中的导航栏徽标居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法使导航栏徽标与它下面的导航链接中心居中对齐.我确定我缺少一些简单的东西,我已经查看了有关此问题的其他几篇文章,但是似乎所有文章都在使用旧版的bootstrap.我目前正在使用Bootstrap 4.0.

I can't seem to get the navbar logo to centre align with the nav-links centre below it. I'm sure I'm missing something simple, I've checked out a few other posts regarding this issue but all seem to be using older versions of bootstrap. I am currently using bootstrap 4.0.

具体地说,我希望徽标位于其自己的单独行中,而不是与链接位于同一行中.

Specifically, I want the logo on its own separate row, not on the same one as the links.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#"><img src="img/h-tech-logo-cropped.png"/></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
  <span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
  <ul class="navbar-nav">
    <li class="nav-item">
      <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Our Services</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">About Us</a>
    </li>
    <li class="nav-item">
      <a class="nav-link disabled" href="#">Gallery</a>
    </li>
    <li class="nav-item">
      <a class="nav-link disabled" href="#">Contact Us</a>
    </li>
  </ul>
</div>

推荐答案

这是使用 flexbox auto-margin 实用程序的问题,如许多其他"Bootstrap 4 Navbar Center"问题...

It's a matter of using the flexbox and auto-margin utils as explained in the many other "Bootstrap 4 Navbar Center" questions...

  • 导航栏为display:flex,因此请使用flex-column创建内容堆栈
  • 使用mx-auto可使自动x轴边距居中.
  • The navbar is display:flex so use flex-column to make content stack
  • Use mx-auto for auto x-axis margins to center.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" >
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" 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" ></script>

<nav class="navbar navbar-expand navbar-light bg-light flex-column">
    <a class="navbar-brand mx-auto" href="#"><img src="img/h-tech-logo-cropped.png"></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Our Services</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">About Us</a>
            </li>
            <li class="nav-item">
                <a class="nav-link disabled" href="#">Gallery</a>
            </li>
            <li class="nav-item">
                <a class="nav-link disabled" href="#">Contact Us</a>
            </li>
        </ul>
    </div>
</nav>

关于Codeply的响应演示

相关的"Bootstrap 4 Navbar Center" 问题:
具有左右对齐项的引导NavBar
引导带有2行的4个导航栏
在Bootstrap 4导航栏中将元素居中
如何在引导程序中将导航项居中?

Related "Bootstrap 4 Navbar Center" questions:
Bootstrap NavBar with left, center or right aligned items
Bootstrap 4 navbar with 2 rows
Center an element in Bootstrap 4 Navbar
How to center nav-items in Bootstrap?

这篇关于如何通过下面的导航链接将Boostrap 4中的导航栏徽标居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 12:34