html – 没有品牌的Center Navbar链接在Bootstrap 4中向右推?

前端之家收集整理的这篇文章主要介绍了html – 没有品牌的Center Navbar链接在Bootstrap 4中向右推?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图将我的导航栏链接放在中心但是当我做我的品牌标识时将其推向右侧,使其不居中.继承人我的HTML …
<nav class="navbar navbar-toggleable-md navbar-light main-nav">
  <button class="navbar-toggler navbar-toggler-right" 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>
  <a class="navbar-brand" href="index.html">Brand Name</a>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mx-auto clearfix">
      <li class="nav-item active">
        <a class="nav-link" href="index.html">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">
        <a class="nav-link" href="#">Link</a>
      </li>
    </ul>

  </div>
</nav>

如何阻止品牌徽标影响导航栏链接的位置.

解决方法

这是因为相邻的flexBox项相对于彼此的位置.

一种选择是使用flexBox utils,右边是一个全宽占位符元素. navbar-brand也使用w-100 util类设置为全宽.

<nav class="navbar navbar-toggleable navbar-inverse bg-primary justify-content-center">
    <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarCenter">
        <span class="navbar-toggler-icon"></span>
    </button>
    <a href class="navbar-brand d-flex w-100 mr-0">Brand is Wider Name</a>
    <div class="navbar-collapse collapse" id="navbarCenter">
        <ul class="navbar-nav mx-auto text-center">
            <li class="nav-item">
                <a class="nav-link" href="#">Link</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Center</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Link</a>
            </li>
        </ul>
    </div>
    <div class="d-flex w-100"> </div>
</nav>

http://www.codeply.com/go/N7veP8FMqg

另一种选择是绝对定位.navbar-nav ..

@media (min-width: 567px) {
    .abs-center-x {
        position: absolute;
        top: 5px;
        left: 50%;
        transform: translateX(-50%);
    }
}

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

有关:
Bootstrap 4 menu toggle button to left and right,with brand in center
How the LOGO could be CENTERED and Not collapsing and toggle icon should appear on left in the Navbar?

原文链接:https://www.f2er.com/html/232060.html

猜你在找的HTML相关文章