From 9d87bd7a30c1874a9c3d60041a4042228753dd0e Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 19 Jan 2021 08:18:19 +0200 Subject: [PATCH] Backport #32037 (#32833) * Backport #32037 Add `.navbar-nav-scroll` for vertical scrolling of navbar content * drop the css var for a Sass css Co-authored-by: Mark Otto --- scss/_navbar.scss | 9 +++++ scss/_variables.scss | 2 + site/content/docs/4.5/components/navbar.md | 45 ++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/scss/_navbar.scss b/scss/_navbar.scss index 5d4b6cd6b885..cf5b667908a2 100644 --- a/scss/_navbar.scss +++ b/scss/_navbar.scss @@ -139,6 +139,11 @@ background: 50% / 100% 100% no-repeat; } +.navbar-nav-scroll { + max-height: $navbar-nav-scroll-max-height; + overflow-y: auto; +} + // Generate series of `.navbar-expand-*` responsive classes for configuring // where your navbar collapses. .navbar-expand { @@ -198,6 +203,10 @@ } } + .navbar-nav-scroll { + overflow: visible; + } + .navbar-collapse { display: flex !important; // stylelint-disable-line declaration-no-important diff --git a/scss/_variables.scss b/scss/_variables.scss index fc02b80e17ef..0a260b96fb6e 100644 --- a/scss/_variables.scss +++ b/scss/_variables.scss @@ -731,6 +731,8 @@ $navbar-toggler-padding-x: .75rem !default; $navbar-toggler-font-size: $font-size-lg !default; $navbar-toggler-border-radius: $btn-border-radius !default; +$navbar-nav-scroll-max-height: 75vh !default; + $navbar-dark-color: rgba($white, .5) !default; $navbar-dark-hover-color: rgba($white, .75) !default; $navbar-dark-active-color: $white !default; diff --git a/site/content/docs/4.5/components/navbar.md b/site/content/docs/4.5/components/navbar.md index 07fff3b35f69..25c5718851ce 100644 --- a/site/content/docs/4.5/components/navbar.md +++ b/site/content/docs/4.5/components/navbar.md @@ -438,6 +438,51 @@ Also note that **`.sticky-top` uses `position: sticky`, which [isn't fully suppo {{< /example >}} +## Scrolling + +Add `.navbar-nav-scroll` to a `.navbar-collapse` (or other navbar sub-component) to enable vertical scrolling within the toggleable contents of a collapsed navbar. By default, scrolling kicks in at `75vh` (or 75% of the viewport height), but you can override that with inline or custom styles. At larger viewports when the navbar is expanded, content will appear as it does in a default navbar. + +Please note that this behavior comes with a potential drawback of `overflow`—when setting `overflow-y: auto` (required to scroll the content here), `overflow-x` is the equivalent of `auto`, which will crop some horizontal content. + +Here's an example navbar using `.navbar-nav-scroll` with `style="max-height: 100px;"`, with some extra margin utilities for optimum spacing. + +{{< example >}} + +{{< /example >}} + ## Responsive behaviors Navbars can use `.navbar-toggler`, `.navbar-collapse`, and `.navbar-expand{-sm|-md|-lg|-xl}` classes to determine when their content collapses behind a button. In combination with other utilities, you can easily choose when to show or hide particular elements.