Back to feed
ForumSpark Support Themes & Extensions Join

Navigation Link Drop-Down Menus

Cory · 7 months ago · 2 replies · 41

Preview

All you need to edit is the following area:

const subLinks = {
    Members: [`<a href="">Test</a>`, `<a href="">Test 2</a>`],
    Search: [`<a href="https://www.google.com/">Google</a>`, `<a href="https://www.yahoo.com/">Yahoo</a>`]
};

Members and Search represent the name of the navigation link you want to append a drop-down menu to, and the HTML can be edited to include the links you want to add to the drop-down menu. Repeat a line and edit to add a drop-down menu. Include a comma after every array except for the last one.

Admin CP → Themes → Board Templates → Head

<style>
a.nav-link:hover {
    display: inline;
}

a.nav-link:hover ul {
    display: flex !important;
    flex-direction: column;
    position: absolute;
    margin-top: .75rem;
    margin-left: -1.30rem !important;
}

a.nav-link li.panel {
    margin: 0 !important;
    border-width: 1px;
}

a.nav-link li.panel:not(:last-child) {
    border-bottom-width: 0;
}

a.nav-link a {
    font-weight: 400;
    display: block;
    padding: .75rem 1.25rem;
}
</style>

Admin CP → Themes → Board Templates → Below the board

<script>
const subLinks = {
    Members: [`<a href="">Test</a>`, `<a href="">Test 2</a>`],
    Search: [`<a href="https://www.google.com/">Google</a>`, `<a href="https://www.yahoo.com/">Yahoo</a>`]
};
const navLinks = document.querySelectorAll('a.nav-link');

if (navLinks) {
    const keys = Object.keys(subLinks);

navLinks.forEach(element => {
    for (const i of keys) {
        if (element.innerText === i) {
            const ul = document.createElement('ul');
            ul.style.display = 'none';
            element.appendChild(ul);

            for (const key of subLinks[i]) {
                const li = document.createElement('li');
                li.className = 'panel';
                li.innerHTML = key;
                element.querySelector('ul').appendChild(li);
            }
        }
    }
});
}
</script>
2 replies
?
Deleted user · 7 months ago

This is very cool. How would I add an arrow to a dropdown?

Cory OP · 7 months ago
Gizmo said:

This is very cool. How would I add an arrow to a dropdown?

Try something like this:

a.nav-link[href$="search"]::after {
    content: '↓';
    padding-left: 5px;
}

search is the string at the end of the URL.

Create a free account to join the conversation.
Sign up free
ForumSpark © 2023 - 2026 · ForumSpark.net · Terms