Disini kita akan membuat menu accordion mengunakan HTML dan CSS, Ok langsung saja kita buat dulu code HTML seperti dibawah ini
<!DOCTYPE html>
<html>
<head>
<title>accordion</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<div class="middle">
<div class="menu">
<li class="item" id="profile">
<a href="#profile" class="btn"><i class="fa fa-user" aria-hidden="true"></i></i>User</a>
<div class="smenu">
<a href="">Login</a>
<a href="">Register</a>
</div>
</li>
<li class="item" id="messages">
<a href="#messages" class="btn"><i class="fa fa-commenting-o" aria-hidden="true"></i></i>Messages</a>
<div class="smenu">
<a href="">New</a>
<a href="">Send</a>
<a href="">Spam</a>
</div>
</li>
<li class="item" id="setting">
<a href="#setting" class="btn"><i class="fa fa-cog" aria-hidden="true"></i></i>Setting</a>
<div class="smenu">
<a href="">Password</a>
<a href="">League</a>
</div>
</li>
<li class="item">
<a class="btn" href=""><i class="fa fa-sign-out" aria-hidden="true"></i>Logout</a>
</li>
</div>
</div>
</body>
</html>
Setelah selesai membuat code HTML kemudian buat fungsi accordion dengan css seperti contoh code dibawah ini
*{
margin: 0;
padding: 0;
font-family: sans-serif;
list-style: none;
text-decoration: none;
}
.middle{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.menu{
width: 300px;
border-radius: 8px;
overflow: hidden;
}
.item{
border-top: 1px solid #2980b9;
overflow: hidden;
}
.btn{
display: block;
padding: 16px 20px;
background: #3498db;
color: white;
}
.btn:before{
content: '';
position: absolute;
width: 14px;
height: 14px;
background: #3498db;
left: 20px;
bottom: -7px;
transform: rotate(45deg);
}
.btn i{
margin-right: 10px;
}
.smenu{
background: #34495e;
overflow: hidden;
transition: max-height 0.3s;
max-height: 0;
}
.smenu a{
display: block;
padding: 16px 26px;
color: white;
font-size: 4px 0;
position: relative;
}
.smenu a:before{
content: '';
position: absolute;
width: 6px;
height: 100%;
background: #3498db;
left: 0;
top: 0;
transition: 0.3s;
opacity: 0;
}
.smenu a:hover:before{
opacity: 1;
}
.item:target .smenu{
max-height: 10em;
}
Semoga bermanfaat berikut adalah cara membuat menu accordion mengunakan HTML dan CSS
0 Komentar