Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add justified navs #18653

Closed
wants to merge 12 commits into from
26 changes: 26 additions & 0 deletions docs/components/navs.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,32 @@ Just add `.nav-stacked` to the `.nav.nav-pills`.
</ul>
{% endexample %}

## Justified navs

Just add `.nav-justified` to the `.nav.nav-tabs` or `.nav.nav-pills`. Easily make tabs or pills equal widths of their parent at screens wider than 768px with `.nav-justified`. On smaller screens, the nav links are stacked. Justified navbar nav links are currently not supported.

### Safari and responsive justified navs
As of v8.0, Safari exhibits a bug in which resizing your browser horizontally causes rendering errors in the justified nav that are cleared upon refreshing. This bug is also shown in the [justified nav example](../examples/justified-nav/).

{% example html %}
<div class="container">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the container necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, i will remove that

<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>
{% endexample %}

## Using dropdowns

Add dropdown menus with a little extra HTML and the [dropdowns JavaScript plugin]({{ site.baseurl }}/components/dropdowns/#usage).
Expand Down
1 change: 1 addition & 0 deletions scss/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@import "mixins/pagination";
@import "mixins/lists";
@import "mixins/list-group";
@import "mixins/nav";
@import "mixins/nav-divider";
@import "mixins/forms";
@import "mixins/progress";
Expand Down
8 changes: 8 additions & 0 deletions scss/_nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@
}
}

//
// Justified
//

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

//
// Dropdowns
Expand Down
60 changes: 60 additions & 0 deletions scss/mixins/_nav.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Justified nav links
// -------------------------

@mixin nav-justified {
width: 100%;

.nav-item {
float: none;
}

.nav-link {
margin-bottom: 5px;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use a variable instead of hardcoding 5px

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;
border-radius: $border-radius;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

.nav-link.active,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make use of the plain-hover-focus mixin here.
See

@mixin plain-hover-focus {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use a variable instead of hardcoding 1px

}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line should be indented 4 spaces, but was indented 3 spaces

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, use plain-hover-focus

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