From 40b15de723114fbfd449e60c443e8956eb62462b Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Mon, 18 Jan 2021 21:32:18 -0800 Subject: [PATCH] Add `.navbar-nav-scroll` for vertical scrolling of navbar content (#32037) Co-authored-by: XhmikosR --- scss/_navbar.scss | 9 ++++ site/content/docs/5.0/components/navbar.md | 48 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/scss/_navbar.scss b/scss/_navbar.scss index 852328aca1..1187d617bd 100644 --- a/scss/_navbar.scss +++ b/scss/_navbar.scss @@ -148,6 +148,11 @@ background-size: 100%; } +.navbar-nav-scroll { + max-height: var(--bs-scroll-height, 75vh); + overflow-y: auto; +} + // Generate series of `.navbar-expand-*` responsive classes for configuring // where your navbar collapses. .navbar-expand { @@ -174,6 +179,10 @@ } } + .navbar-nav-scroll { + overflow: visible; + } + .navbar-collapse { display: flex !important; // stylelint-disable-line declaration-no-important } diff --git a/site/content/docs/5.0/components/navbar.md b/site/content/docs/5.0/components/navbar.md index e59c7c25b9..72a61581b8 100644 --- a/site/content/docs/5.0/components/navbar.md +++ b/site/content/docs/5.0/components/navbar.md @@ -31,6 +31,7 @@ Navbars come with built-in support for a handful of sub-components. Choose from - Flex and spacing utilities for any form controls and actions. - `.navbar-text` for adding vertically centered strings of text. - `.collapse.navbar-collapse` for grouping and hiding navbar contents by a parent breakpoint. +- Add an optional `.navbar-scroll` to set a `max-height` and [scroll expanded navbar content](#scrolling). Here's an example of all the sub-components included in a responsive light-themed navbar that automatically collapses at the `lg` (large) breakpoint. @@ -477,6 +478,53 @@ 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 the local CSS custom property `--bs-navbar-height` 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="--bs-scroll-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|-xxl}` 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.