Simple Responsive Accordion List

In this example below you will see how to do a Simple Responsive Accordion List with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by rmenner, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright rmenner ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Simple Responsive Accordion List </title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  
<div class="accordian-wrap">
  <div class="item active">
    <div class="title-wrap">
      <div class="title">
        <span class="pow">Q</span>
        <span class="text">What does Lorem Ipsum look like?</span>
      </div>
    </div>
    <div class="body-wrap">
      <div class="body">
        
<p><span class="pow">A</span> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>  
      </div>
    </div>
  </div>
  <div class="item">
    <div class="title-wrap">
      <div class="title">
        <span class="pow">Q</span>
        <span class="text">What does Lorem Ipsum look like?</span>
      </div>
    </div>
    <div class="body-wrap">
      <div class="body">
        
<p><span class="pow">A</span> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>  
      </div>
    </div>
  </div>
  <div class="item">
    <div class="title-wrap">
      <div class="title">
        <span class="pow">Q</span>
        <span class="text">What does Lorem Ipsum look like?</span>
      </div>
    </div>
    <div class="body-wrap">
      <div class="body">
        <p><span class="pow">A</span> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>  
      </div>
    </div>
  </div>
  <div class="item">
    <div class="title-wrap">
      <div class="title">
        <span class="pow">Q</span>
        <span class="text">What does Lorem Ipsum look like?</span>
      </div>
    </div>
    <div class="body-wrap">
      <div class="body">
        <p><span class="pow">A</span> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> 
      </div>
    </div>
  </div>
</div>
<div class="accordian-wrap">
  <div class="item active">
    <div class="title-wrap">
      <div class="title">
        <span class="pow">1.</span>
        <span class="text">Lorem ipsum dolor sit amet</span>
      </div>
    </div>
    <div class="body-wrap">
      <div class="body">
        
<p><span class="pow">1a:</span> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
<p><span class="pow">1b:</span> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>  
      </div>
    </div>
  </div>
  <div class="item">
    <div class="title-wrap">
      <div class="title">
        <span class="pow">2.</span>
        <span class="text">Consectetur adipisicing elit</span>
      </div>
    </div>
    <div class="body-wrap">
      <div class="body">
        
<p><span class="pow">2a:</span> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>  
      </div>
    </div>
  </div>
  <div class="item">
    <div class="title-wrap">
      <div class="title">
        <span class="pow">3.</span>
        <span class="text">Eveniet natus expedita, cumque ea voluptatibus</span>
      </div>
    </div>
    <div class="body-wrap">
      <div class="body">
        <p><span class="pow">3a:</span> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>  
      </div>
    </div>
  </div>
</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>

/*Downloaded from https://www.codeseek.co/rmenner/simple-responsive-accordion-list-bdOpBN */
.accordian-wrap {
  padding: 1em;
  border-radius: 10px;
}
.accordian-wrap .title-wrap {
  background-color: #fff;
  padding: 1em;
  border-radius: 5px;
  border: 1px solid #ddd;
  cursor: pointer;
}
.accordian-wrap .title-wrap .title {
  font-size: 1.3em;
  font-family: sans-serif;
  color: #005599;
  line-height: 1.5em;
}
.accordian-wrap .title-wrap .title .pow {
  font-size: 1.6em;
  position: relative;
  bottom: -.1em;
  margin-right: .1em;
  font-weight: bold;
}
.accordian-wrap .body-wrap {
  padding: .5em;
  margin: 0 .3em;
  background-color: #efefef;
  border-top: 0;
}
.accordian-wrap .body-wrap .body {
  display: none;
  padding: .5em;
  font-size: 1.1em;
  font-family: sans-serif;
  color: #6B6B6B;
  font-weight: 100;
  line-height: 1.5em;
}
.accordian-wrap .body-wrap .body p:nth-last-child(1) {
  margin-bottom: 0 !important;
}
.accordian-wrap .body-wrap .body p:nth-child(1) {
  margin-top: 0 !important;
}
.accordian-wrap .body-wrap .body p:nth-last-child(1):nth-child(1) {
  margin: 0 !important;
}
.accordian-wrap .body-wrap .body .pow {
  font-size: 1.7em;
  position: relative;
  bottom: -.1em;
  font-weight: bold;
  margin-right: 0.1em;
}
.accordian-wrap .item.active .body {
  display: block;
}
.accordian-wrap .item.active .title-wrap {
  cursor: default;
}


/*Downloaded from https://www.codeseek.co/rmenner/simple-responsive-accordion-list-bdOpBN */
$('.accordian-wrap .item .title-wrap').click( function(){
  if(!$(this).parent().hasClass('active')){
    $parent = $(this).parent().parent();
    $('.item',$parent).removeClass('active');
    $(this).parent().addClass('active');
  }
});

Comments