Skip to content

Commit f4c01ac

Browse files
adds submenu in navigation bar. (fixes issue alshedivat#159) (alshedivat#334)
* adds submenu in navigation bar. (fixes issue alshedivat#159) * Updated scss files to change hover animations on dropdown submenus, on both dark mode and light mode
1 parent e328dc6 commit f4c01ac

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

_includes/header.html

+20
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@
4646
{% assign sorted_pages = site.pages | sort: "title" %}
4747
{% for p in sorted_pages %}
4848
{% if p.nav and p.autogen == nil %}
49+
{% if p.dropdown %}
50+
<li class="nav-item dropdown {% if page.title == p.title %}active{% endif %}">
51+
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
52+
{{ p.title }}
53+
{% if page.title == p.title %}
54+
<span class="sr-only">(current)</span>
55+
{% endif %}
56+
</a>
57+
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
58+
{% for child in p.children %}
59+
{% if child.title == 'divider' %}
60+
<div class="dropdown-divider"></div>
61+
{% else %}
62+
<a class="dropdown-item" href="{{ child.permalink | relative_url }}">{{ child.title }}</a>
63+
{% endif %}
64+
{% endfor %}
65+
</div>
66+
</li>
67+
{% else %}
4968
<li class="nav-item {% if page.title == p.title %}active{% endif %}">
5069
<a class="nav-link" href="{{ p.url | relative_url }}">
5170
{{ p.title }}
@@ -55,6 +74,7 @@
5574
</a>
5675
</li>
5776
{% endif %}
77+
{% endif %}
5878
{% endfor %}
5979
{% if site.enable_darkmode %}
6080
<div class = "toggle-container">

_pages/dropdown.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
layout: page
3+
title: submenus
4+
nav: true
5+
dropdown: true
6+
children:
7+
- title: publications
8+
permalink: /publications/
9+
- title: divider
10+
- title: projects
11+
permalink: /projects/
12+
---

_sass/_base.scss

+17-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ a, table.table a {
1414
color: var(--global-theme-color);
1515
text-decoration: underline;
1616
}
17-
&:hover:after {
17+
&:hover:after :not(.nav-item.dropdown) {
1818
width: 100%;
1919
}
2020
}
@@ -95,6 +95,22 @@ blockquote {
9595
background-color: var(--global-bg-color);
9696
opacity: 0.95;
9797
}
98+
.navbar .dropdown-menu {
99+
background-color: var(--global-bg-color);
100+
a:not(.active) {
101+
color: var(--global-text-color);
102+
}
103+
a:hover {
104+
color: var(--global-hover-color);
105+
}
106+
}
107+
.dropdown-item {
108+
color: var(--global-text-color);
109+
&:hover {
110+
color: var(--global-hover-color);
111+
background-color: var(--global-bg-color);
112+
}
113+
}
98114
.navbar.navbar-light {
99115
a {
100116
&:hover {

0 commit comments

Comments
 (0)