"Bootstrap 4 accordion dropdown menu snippets"
Bootstrap 4.1.1 Snippet by techadmin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<ul id="accordion" class="accordion">
<li>
<div class="link"><i class="fa fa-laptop"></i>Laptops<i class="fa fa-chevron-down"></i></div>
<ul class="submenu">
<li><a href="#">Dell Acron</a></li>
<li><a href="#">HP Envy</a></li>
<li><a href="#">Macbook Air</a></li>
</ul>
</li>
<li>
<div class="link"><i class="fa fa-tv"></i>Smart TV<i class="fa fa-chevron-down"></i></div>
<ul class="submenu">
<li><a href="#">Sony Bravia</a></li>
<li><a href="#">Samsung</a></li>
<li><a href="#">MI</a></li>
</ul>
</li>
<li>
<div class="link"><i class="fa fa-mobile"></i>Mobiles<i class="fa fa-chevron-down"></i></div>
<ul class="submenu">
<li><a href="#">Samsung S9</a></li>
<li><a href="#">Apple X</a></li>
<li><a href="#">Honor Play</a></li>
</ul>
</li>
<li>
<div class="link"><i class="fa fa-globe"></i>Search Engines<i class="fa fa-chevron-down"></i></div>
<ul class="submenu">
<li><a href="#">Google</a></li>
<li><a href="#">Bing</a></li>
<li><a href="#">Yahoo</a></li>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
* {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box
}
.container {
margin-top: 150px
}
body {
background: #005C97;
background: -webkit-linear-gradient(left, #363795, #005C97);
background: -moz-linear-gradient(left, #363795, #005C97);
background: -o-linear-gradient(left, #363795, #005C97);
background: linear-gradient(to right, #363795, #005C97);
font-family: 'Open Sans', Arial, Helvetica, Sans-serif, Verdana, Tahoma
}
ul {
list-style-type: none
}
a {
color: #b63b4d;
text-decoration: none
}
.accordion {
width: 100%;
max-width: 584px;
margin: 30px auto 20px;
background: #FFF;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$(function() {
var Accordion = function(el, multiple) {
this.el = el || {};
this.multiple = multiple || false;
var links = this.el.find('.link');
links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown)
}
Accordion.prototype.dropdown = function(e) {
var $el = e.data.el;
$this = $(this),
$next = $this.next();
$next.slideToggle();
$this.parent().toggleClass('open');
if (!e.data.multiple) {
$el.find('.submenu').not($next).slideUp().parent().removeClass('open');
};
}
var accordion = new Accordion($('#accordion'), false);
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: