-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccordion.html
142 lines (130 loc) · 3.52 KB
/
Accordion.html
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Accordion</title>
<style>
*{
margin:0;
padding:0;
box-sizing:border-box;
}
body{
display:flex;
align-items:center;
justify-content:center;
height:100vh;
}
.container{
width:300px;
box-shadow: 0 0 5px #ccc;
padding:20px;
}
.items .btn{
font-family:sans-serif;
font-size:20px;
font-weight:800;
text-transform:capitalize;
text-align:left;
border:none;
background:none;
outline:none;
background:#ccc;
padding:10px 30px;
position:relative;
width:100%;
height:auto;
border-radius:5px;
margin-bottom:10px;
cursor:pointer;
transition:1s ease;
}
.items .btn:hover,
.items .btn.active{
background:#909090;
color:#fff;
}
.items .btn:after,
.items .btn:before{
position:absolute;
content:"";
width:10px;
height:2px;
background:#000;
right:10%;
top:50%;
transform:translateY(-50%);
transition:1s;
}
.items .btn:before{
transform:translateY(-50%) rotate(90deg);
}
.items .btn:hover:after,
.items .btn:hover:before{
background:#fff;
}
.items .btn.active:after{
transform:translateY(-50%) rotate(-90deg);
opacity:0;
}
.items .btn.active:before{
transform:translateY(-50%) rotate(0deg);
background:#fff;
}
.items .content{
box-shadow:0 0 5px #ccc;
border-radius:5px;
margin-bottom:10px;
padding:0 10px;
max-height:0;
overflow:hidden;
transition:1s max-height;
}
.items .content.show{
max-height:150px;
}
.content p{
text-align:justify;
font-family:poppins;
font-size:15px;
font-weight:400;
padding:10px;
}
</style>
</head>
<body>
<div class="container">
<div class="items">
<button class="btn">Accordion Button</button>
<div class="content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
<div class="items">
<button class="btn">Accordion Button</button>
<div class="content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
<div class="items">
<button class="btn">Accordion Button</button>
<div class="content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</div>
<script>
var btn = document.querySelectorAll(".btn");
// start a loop
for(var i = 0; i < btn.length; i++){
//separate click function
btn[i].addEventListener("click", function(){
this.classList.toggle("active");
this.nextElementSibling.classList.toggle("show");
});
}
</script>
</body>
</html>