Wed Jul 06 2022
Custom Accordion
CSS836 views
File Name: html-css-accordion.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accordion</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
body {
background-color: #383838;
}
section {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
ul#accordion {
width: 450px;
list-style: none;
}
ul#accordion li {
background-color: rgba(255, 255, 255, 0.3);
padding: 20px;
border-radius: 20px;
margin: 10px 0;
}
ul#accordion li h3 {
color: #fff;
font-size: 18px;
margin: 0;
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
}
ul#accordion li h3 svg {
width: 25px;
height: 25px;
transition: 0.2s all ease-in-out;
}
ul#accordion li h3.active svg {
transform: rotate(-180deg);
}
ul#accordion li div {
margin-top: 10px;
display: none;
}
ul#accordion li div p {
color: #ececec;
font-size: 15px;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script>
$(document).ready(function () {
$("#accordion li h3").click(function () {
$(this).toggleClass('active');
$(this).next('div').slideToggle();
});
});
</script>
</head>
<body>
<section>
<ul id="accordion">
<li>
<h3>
Lorem ipsum dolor, sit
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7" />
</svg>
</h3>
<div>
<p>Amet consectetur adipisicing elit. Perferendis, qui similique dolore repellat fuga maiores suscipit officiis adipisci? Distinctio impedit error ipsa suscipit quisquam dolore vitae adipisci inventore voluptatum cumque!</p>
</div>
</li>
<li>
<h3>
Lorem ipsum dolor, sit
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7" />
</svg>
</h3>
<div>
<p>Amet consectetur adipisicing elit. Perferendis, qui similique dolore repellat fuga maiores suscipit officiis adipisci? Distinctio impedit error ipsa suscipit quisquam dolore vitae adipisci inventore voluptatum cumque!</p>
</div>
</li>
<li>
<h3>
Lorem ipsum dolor, sit
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7" />
</svg>
</h3>
<div>
<p>Amet consectetur adipisicing elit. Perferendis, qui similique dolore repellat fuga maiores suscipit officiis adipisci? Distinctio impedit error ipsa suscipit quisquam dolore vitae adipisci inventore voluptatum cumque!</p>
</div>
</li>
<li>
<h3>
Lorem ipsum dolor, sit
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7" />
</svg>
</h3>
<div>
<p>Amet consectetur adipisicing elit. Perferendis, qui similique dolore repellat fuga maiores suscipit officiis adipisci? Distinctio impedit error ipsa suscipit quisquam dolore vitae adipisci inventore voluptatum cumque!</p>
</div>
</li>
</ul>
</section>
</body>
</html>
Result Screenshot(s)
Author:Geekboots