如何在不将徽标品牌移到中间的情况下修复中心菜单?

时间:2019-02-02 22:00:48

标签: twitter-bootstrap css3

我想使导航栏菜单居中,但我也不想让徽标导航栏品牌移动,但我也尝试将文本居中,但似乎无济于事..我更新了代码并删除了容器类,但第二个列表中的第三个列表

.nav.navbar-nav {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}
@media (min-width: 768px) {
    .navbar-nav {
        float: none;
    }
}

html

<div class="wrapper">
  <!-- Header-->
  <nav class="navbar navbar-default" role="navigation">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
    </div>
    <div class="nav-bar-container">
      <ul class="nav navbar-nav navbar-left">
        <li><a href="#">Left</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-center">
        <li><a href="#">Center 1</a></li>
        <li><a href="#">Center 2</a></li>
        <li><a href="#">Center 3</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Right</a></li>
      </ul>
    </div>
  </nav>
</div>

添加后的问题

.nav.navbar-nav {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}


.nav-bar-container{
  display: flex;
  justify-content: space-between;
}

@media (max-width: 768px) {
    .nav-bar-container{
        display: none;
    }
}

center

1 个答案:

答案 0 :(得分:0)

我建议删除容器类并添加您自己的容器类,因为它有一些!important规则。使用

display: flex;
justify-content: space-between;

.nav.navbar-nav {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
}


.nav-bar-container{
  display: flex;
  justify-content: space-between;
}

@media (max-width: 768px) {
    .nav-bar-container{
        display: none;
    }
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<div class="wrapper">
  <!-- Header-->
  <nav class="navbar navbar-default" role="navigation">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
    </div>
    <div class="nav-bar-container">
      <ul class="nav navbar-nav navbar-left">
        <li><a href="#">Left</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-center">
        <li><a href="#">Center 1</a></li>
        <li><a href="#">Center 2</a></li>
        <li><a href="#">Center 3</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Right</a></li>
      </ul>
    </div>
  </nav>
</div>