6

我想在 div 的宽度上证明我的导航栏是合理的。问题是我使用Bootstrap v4nav-justify类还不可用。

这是代码:

<ul class="nav nav-pills">
    <li class="nav-item">
        <a class="nav-link active" href="#subscribed" data-toggle="tab">Mes inscriptions</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" href="#eventPassed" data-toggle="tab">Événements passés</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" href="#eventNow" data-toggle="tab">Événements en cours</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" href="#eventIncoming" data-toggle="tab">Événements futurs</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" href="#eventCreation" data-toggle="tab">Créer un événement</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" href="#eventOwn" data-toggle="tab">Mes événements</a>
    </li>
</ul>

我不想在 CSS 中使用百分比来做到这一点;我想要一些反应灵敏的东西。

4

3 回答 3

4

确实nav-justify class丢失了。您现在可以根据 TB3 的代码自行添加:

SCSS代码:

// Justified nav links
// -------------------------

@mixin nav-justified {
  width: 100%;

  .nav-item {
    float: none;
  }

  .nav-link {
    text-align: center;
    margin-bottom: 5px;
  }

  > .dropdown .dropdown-menu { //todo: remove child selector
    top: auto;
    left: auto;
  }

  @include media-breakpoint-up(sm) {
    .nav-item {
      display: table-cell;
      width: 1%;
    }
    .nav-link {
        margin-bottom: 0;
    }
  }
}

// Move borders to anchors instead of bottom of list
//
// Mixin for adding on top the shared `.nav-justified` styles for our tabs
@mixin nav-tabs-justified {
  border-bottom: 0;

  .nav-link {
    // Override margin from .nav-tabs
    margin-right: 0;
    border-radius: $border-radius;
  }

  .nav-link.active,
  .nav-link.active:hover,
  .nav-link.active:focus {
    border: 1px solid $nav-tabs-justified-link-border-color;
  }

  @include media-breakpoint-up(sm) {
    .nav-link {
      border-bottom: 1px solid $nav-tabs-justified-link-border-color;
      border-radius: $border-radius $border-radius 0 0;
    }
   .nav-link.active,
   .nav-link.active:hover,
   .nav-link.active:focus {
      border-bottom-color: $nav-tabs-justified-active-link-border-color;
    }
  }
}

.nav-justified {
  @include nav-justified;
  @include nav-tabs-justified;
}

编译的 CSS 代码:

.nav-justified {
  width: 100%;
  border-bottom: 0; }
  .nav-justified .nav-item {
    float: none; }
  .nav-justified .nav-link {
    text-align: center;
    margin-bottom: 5px; }
  .nav-justified > .dropdown .dropdown-menu {
    top: auto;
    left: auto; }
  @media (min-width: 544px) {
    .nav-justified .nav-item {
      display: table-cell;
      width: 1%; }
    .nav-justified .nav-link {
      margin-bottom: 0; } }
  .nav-justified .nav-link {
    margin-right: 0;
    border-radius: 0.25rem; }
  .nav-justified .nav-link.active,
  .nav-justified .nav-link.active:hover,
  .nav-justified .nav-link.active:focus {
    border: 1px solid #ddd; }
  @media (min-width: 544px) {
    .nav-justified .nav-link {
      border-bottom: 1px solid #ddd;
      border-radius: 0.25rem 0.25rem 0 0; }
    .nav-justified .nav-link.active,
    .nav-justified .nav-link.active:hover,
    .nav-justified .nav-link.active:focus {
      border-bottom-color: #fff; } }

HTML

<div class="container">
<ul class="nav nav-pills nav-justified">
  <li class="nav-item">
    <a class="nav-link active" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Another link</a>
  </li>
  <li class="nav-item">
    <a class="nav-link disabled" href="#">Disabled</a>
  </li>
</ul>
</div>

大屏幕 在此处输入图像描述

小屏幕 在此处输入图像描述

更新:从 BS4 alpha 6 开始,它又nav-justified回来了,还有一个新类nav-fill http://v4-alpha.getbootstrap.com/components/navs/#fill-and-justify

于 2015-12-23T10:01:01.040 回答
2

从 Bootstrap alpha 6 开始,它又nav-justified回来了,并且有一个新nav-fill类。

http://v4-alpha.getbootstrap.com/components/navs/#fill-and-justify

您只需要将课程添加到您的nav..

<ul class="nav nav-pills nav-justified">
        ..
</ul>

Bootstrap 4 合理导航

于 2017-02-23T21:24:36.620 回答
1

他们在 Boostrap 的文档中有它v.4 alpha在这个页面上,但现在它已经坏了。

这个有相应的,并且已经创建了分支的拉取请求v4-dev

在这里发布整个代码片段没有任何意义,因此您可能会在此处看到更改,并为您自己的 SASS 文件打补丁:

// Justified nav links
// -------------------------

@mixin nav-justified {
  width: 100%;

  .nav-item {
    float: none;
  }

  .nav-link {
    margin-bottom: $nav-tabs-justified-link-margin-bottom;
    text-align: center;
  }

  .dropdown .dropdown-menu {
    top: auto;
    left: auto;
  }

  @include media-breakpoint-up(md) {
    .nav-item {
      display: table-cell;
      width: 1%;
    }
    .nav-link {
      margin-bottom: 0;
    }
  }
}

// Move borders to anchors instead of bottom of list
//
// Mixin for adding on top the shared `.nav-justified` styles for our tabs
@mixin nav-tabs-justified {
  border-bottom: 0;

  .nav-link { // Override margin from .nav-tabs
    margin-right: 0;
    @include border-radius($nav-tabs-justified-link-border-radius);
  }

  .nav-link.active {
    @include plain-hover-focus {
      border: $nav-tabs-justified-link-border-width solid $nav-tabs-justified-link-border-color;
    }
  }

  @include media-breakpoint-up(md) {
    .nav-link,
    .nav-link.disabled,
    .nav-link.disabled:hover {
      border-bottom: $nav-tabs-justified-link-border-width solid $nav-tabs-justified-link-border-color;
      @include border-top-radius($nav-tabs-justified-link-border-radius);
    }
    .nav-link.active {
      @include plain-hover-focus {
        border-bottom-color: $nav-tabs-justified-active-link-border-color;
      }
    }
  }
}
于 2016-03-31T10:05:58.223 回答