Creating a third level dropdown menu for NationBuilder sites using Bootstrap 4
Creating a multilevel dropdown menu NationBuilder websites with Bootstrap 4
With Bootstrap 4 it is not quite as easy to add a multilevel dropdown to the top navigation, as the “dropdown-menu” is a
<div> element with an
<a> link inside, where that
<a> can’t contain other links within it. For the third level we mostly will need to create it inside the second level “dropdown-item(s)” to “absolute” position the new “dropdown-submenu” on each of the children of the second level. So the sub “dropdown-menu” must come with a “position:absolute;”, “top:0;”, and positioned just at the right side of its parents in the second level, but this can’t be done within
In Bootstrap 3 the “dropdown-menu” used to be a
<ul> item, inside another
<li> inside another
<ul> list of items, which made it possible to create another sub “dropdown-menu” inside the final
<li> element without being directly inside the
To make a third level of navigation possible with Bootstrap 4, we we will make a couple of changes in the HTML and some styling, creating some new
We will first be creating the “dropdown-item(s)” as a new unordered list (
<ul>) with class “dropdown-item-ul”, then
<li> elements with class “dropdown-item-li” which will contain the “dropdown-submenu” (or the 3rd level nav) and an
<a> element with class “dropdown-item-a”.
This is an example solution based on the liquid programming language as applied to NationBuilder pages. However, the idea is the same for any Bootstrap 4 nav.
Now let’s get started!
Download the two HTML files and use them to replace the Bootstrap 4 default “nav.html”. You will need to replace the
liquid line of code with the below two lines within the “layout.html” file.
Download the two SCSS files in Github, copy the styles into your own stylesheets or attach the provided “.scss” stylesheets directly to your site through the “theme.scss” file, adding the lines of code as below.
@import "styles_mobile"; @import "styles_desktop";
The nav will look similar to the example image below for, but with some colour differences. Edit the styles for any changes, removing the hover border bottom, create different hover effects, adapt a logo or remove the :last-child styles for the last item in the nav.
This is a base that works from desktop to mobile with some effects, some default styles and colors and applying some Bootstrap 4 classes too - changes can also be made to the HTML or SCSS.
Have any questions? We're always happy to help
Get in touch on email: firstname.lastname@example.org