Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                 <section class="card">
  <article>
    <h1 data-accordion-element-trigger>Lorem ipsum</h1>
    <div data-accordion-element-content class="content">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eu lectus quis mauris malesuada fringilla. Praesent non tellus massa. Phasellus at neque et massa elementum sodales. Quisque neque enim, dignissim at molessllis. Pellentesque blandit quam imperdiet lorem lobortis, at pharetra massa condimentum. Maecenas ac nibh mi. Donec suscipit dolor vitae faucibus venenatis.</p>
    </div>
  </article>
  <article>
    <h1 data-accordion-element-trigger>Lorem ipsum dolor sit amet, consect</h1>
    <div data-accordion-element-content class="content">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eu lectus quis mauris malesuada fringilla. Praesent non tellus massa. Phasellus at neque et massa elementum sodales. Quisque neque enim, dignissim at molestie quis, lobortis eu elit. </p>
    </div>
  </article>
  <article>
    <h1 data-accordion-element-trigger>Lorem ipsum</h1>
    <div data-accordion-element-content class="content">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eu lectus quis mauris malesuada fringilla. Praesent non tellus massa. Phasellus at neque et massa elementum sodales. Quisque neque enim, dignissim at molestie quis, lobortis eu elit. Sed ornare ultrices tortor sed mollis. Pellentesque blandit quam imperdiet lorem lobortis, at pharetra massa condimentum. Maecenas ac nibh mi. Donec suscipit dolor vitae faucibus venenatis.</p>
    </div>
  </article>
  <article>
    <h1 data-accordion-element-trigger>Lorem ipsum</h1>
    <div data-accordion-element-content class="content">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eu lectus quis mauris malesuada fringilla. Praesent non tellus massa. Phasellus at neque et massa elementum sodales. Quisque neque enim, dignissim at molestie quis, lobortis eu elit. Sed ornare ultrices tortor sed mollis. Pellentesque blandit quam imperdiet lorem lobortis, at pharetra massa condimentum. Maecenas ac nibh mi. Donec suscipit dolor vitae faucibus venenatis.<br />Praesent non tellus massa. Phasellus at neque et massa elementum sodales. Quisque neque enim, dignissim at molestie quis, lobortis eu elit. Sed ornare ultrices tortor sed mollis. Pellentesque blandit quam imperdiet lorem lobortis, at pharetra massa condimentum. Maecenas ac nibh mi. Donec suscipit dolor vitae faucibus venenatis.</p>
    </div>
  </article>
</section>
              
            
!

CSS

              
                // NECESSARY
 
[data-accordion-element-content] {
  height: auto;
  overflow: hidden;
  transition: height .5s;
}

// JUST TO STYLE THIS PEN

* {
  box-sizing: border-box;
}

body {
    background: #eee;
    overflow: scroll;
}

.card {
  width: 400px;
  margin: 50px auto;
  border-radius: 2px;
  background: white;
  box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 1px 5px 0 rgba(0,0,0,0.12), 0 3px 1px -2px rgba(0,0,0,0.2);
}
  
article {
  position: relative;
  font-family: 'Roboto', sans-serif;
  transition: all .3s;
  background: #E8EAF6;
  
  &.selected {
    transform: scale(1.1);
    box-shadow: 0 0 5px rgba(2, 2, 2, 0.4);
    z-index: 2;
  } 
}
  
h1 {
  position: relative;
  background: #3F51B5;
  padding: 20px 75px 20px 30px;
  font-size: 20px;
  line-height: 30px;
  color: #fff;
  overflow: hidden;
  transition: background .3s;
  
  &:hover,
  .selected & {
    cursor: pointer;
    background: #3949AB;
  }

  &:before,
  &:after {
    content: "";
    position: absolute;
    right: 0;
    top: 50%;
    margin-top: -1px;
    margin-right: 30px;
    width: 20px;
    height: 2px;
    background: #fff;
    transition: transform .3s;
  }

  &:before {
    transform: rotate(0deg);
    animation: close-line-one-in .8s forwards;
    
    .selected & {
      animation: close-line-one-out .8s forwards;
    }
  }
  
  &:after {
    transform: rotate(90deg);
    animation: close-line-two-in .8s forwards;
    
    .selected & {
      animation: close-line-two-out .8s forwards;  
    }
  }

}

.content {  
  opacity: 0;
  transform: translateY(20px);
  transition: all ease-out .4s .1s;
  
  .selected & {
    transform: translateY(0);
    opacity: 1;
  }
  
  .collapsed & {
    display: none;
  }
}

p {
  padding: 25px 30px 40px;
  background: #E8EAF6;
  font-size: 16px;
  line-height: 24px;
  color: #000;
}


@keyframes close-line-one-out {
    0%, 50% {
      transform: translateX(0);
    }
    75% { 
      transform: translateX(50px);
    }
    76% { 
      transform: translateX(50px) translateY(50px);
    }
    100% { 
      transform: rotate(45deg);
    }
}

@keyframes close-line-one-in {
    0%, 20% {
      transform: rotate(45deg);
    }
    60% { 
      transform: translateX(50px) translateY(50px) rotate(45deg);
    }
    61% { 
      transform: translateX(50px);
    }
    100% { 
      transform: rotate(0deg);
    }
}

@keyframes close-line-two-out {
    0%, 50% { 
      transform: rotate(90deg);
    }
    75% { 
      transform: translateY(-50px) rotate(90deg);
    }
    76% {
      transform: translateY(-50px) translateX(50px) rotate(90deg);
    }
    100% { 
      transform: rotate(135deg);
    }
}

@keyframes close-line-two-in {
    0% { 
      transform: rotate(135deg);
    }
    50% { 
      transform: translateY(-50px) translateX(50px) rotate(135deg);
    }
    51% { 
      transform: translateY(-50px) rotate(90deg);
    }
    100% { 
      transform: rotate(90deg);
    }
}
              
            
!

JS

              
                /**
>>>>>>>

Wanna include in your project?

More documentation on github:

https://github.com/cant89/gianni-accordion-js

>>>>>>>
**/

var myAccordion = new gianniAccordion({
  elements: ".card article",
          trigger: "[data-accordion-element-trigger]",
        content: "[data-accordion-element-content]",
});

myAccordion.on("elementSelected", (data)=>{
  console.log("elementOpened", data);
});
              
            
!
999px

Console