Simple Accordion

Developer
Size
3,683 Kb
Views
22,264

How do I make an simple accordion?

Accordion, simple jQuery with toggle icon.. What is a simple accordion? How do you make a simple accordion? This script and codes were developed by B. on 21 December 2022, Wednesday.

Simple Accordion Previews

Simple Accordion - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Simple Accordion</title> <link rel="stylesheet" href="https://s3.amazonaws.com/icomoon.io/27718/CodePen/style.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ html { font-size: 100%; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%;
}
body { background-color: #1e242b; color: white; font-size: 100%; font-weight: normal; font-style: normal; line-height: 1.5; margin: 0; -webkit-font-smoothing: antialiased;
}
* { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;
}
h1, h2, h3, h4, h5, h6 { font-size: 1em; font-weight: 400;
}
.accordion--faq { max-width: 550px; margin: 1em auto;
}
.accordion--faq .accordion__question:last-child { border-bottom: 1px solid white;
}
.accordion--faq .accordion__header { border-top: 1px solid white; cursor: pointer; display: inline-block; letter-spacing: 0.031em; line-height: 2.3; padding: 0.5em 1em; width: 100%;
}
.accordion--faq .accordion__header:hover span, .accordion--faq .accordion__header:focus span { color: white;
}
.accordion--faq .accordion__header.is-active span { color: white;
}
.accordion--faq .accordion__header.is-active span:before { content: "\e0c4";
}
.accordion--faq .accordion__header span { display: inline-block; color: #4e606d; line-height: 2.3; float: right;
}
.accordion--faq .accordion__heading { display: inline-block; margin: 0;
}
.accordion--faq .accordion__content { display: none; padding: 1em;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <!-- Need to add ARIA -->
<div class="accordion accordion--faq"> <section class="accordion__question"> <header class="accordion__header"> <h5 class="accordion__heading">Lets ask a question?</h5> <span class="icon-arrow-down"></span> </header> <div class="accordion__content"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa lorem, eleifend vitae rhoncus viverra, hendrerit ac tellus.</p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa lorem, eleifend vitae rhoncus viverra, hendrerit ac tellus.</p> </div> </section> <section class="accordion__question"> <header class="accordion__header"> <h5 class="accordion__heading">Lets ask a question?</h5> <span class="icon-arrow-down"></span> </header> <div class="accordion__content"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa lorem, eleifend vitae rhoncus viverra, hendrerit ac tellus.</p> </div> </section> <section class="accordion__question"> <header class="accordion__header"> <h5 class="accordion__heading">Lets ask a question?</h5> <span class="icon-arrow-down"></span> </header> <div class="accordion__content"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa lorem, eleifend vitae rhoncus viverra, hendrerit ac tellus.</p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa lorem, eleifend vitae rhoncus viverra, hendrerit ac tellus.</p> </div> </section>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Simple Accordion - Script Codes CSS Codes

html { font-size: 100%; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%;
}
body { background-color: #1e242b; color: white; font-size: 100%; font-weight: normal; font-style: normal; line-height: 1.5; margin: 0; -webkit-font-smoothing: antialiased;
}
* { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;
}
h1, h2, h3, h4, h5, h6 { font-size: 1em; font-weight: 400;
}
.accordion--faq { max-width: 550px; margin: 1em auto;
}
.accordion--faq .accordion__question:last-child { border-bottom: 1px solid white;
}
.accordion--faq .accordion__header { border-top: 1px solid white; cursor: pointer; display: inline-block; letter-spacing: 0.031em; line-height: 2.3; padding: 0.5em 1em; width: 100%;
}
.accordion--faq .accordion__header:hover span, .accordion--faq .accordion__header:focus span { color: white;
}
.accordion--faq .accordion__header.is-active span { color: white;
}
.accordion--faq .accordion__header.is-active span:before { content: "\e0c4";
}
.accordion--faq .accordion__header span { display: inline-block; color: #4e606d; line-height: 2.3; float: right;
}
.accordion--faq .accordion__heading { display: inline-block; margin: 0;
}
.accordion--faq .accordion__content { display: none; padding: 1em;
}

Simple Accordion - Script Codes JS Codes

var accordionHeader = $('.accordion__header'), accordionContent = $('.accordion__content'), accordionIcon = $('.accordion__header span');
$(accordionHeader).click(function () { if ($(this).hasClass('is-active')){ $(this).next(accordionContent).slideUp('slow'); $(this).removeClass('is-active'); } else { // close other content $(accordionHeader).not(this).next(accordionContent).slideUp('slow'); $(accordionHeader).not(this).removeClass('is-active'); $(this).next(accordionContent).slideDown('slow'); $(this).addClass('is-active'); }
});
Simple Accordion - Script Codes
Simple Accordion - Script Codes
Home Page Home
Developer B.
Username wearebold
Uploaded December 21, 2022
Rating 3.5
Size 3,683 Kb
Views 22,264
Do you need developer help for Simple Accordion?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

B. (wearebold) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!