Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <pattern id="pattern"
           x="0" y="0" width="24" height="24"
           patternUnits="userSpaceOnUse" >
    <rect fill="rgba(159, 188, 191, 0.15)" x="0" width="20" height="20" y="0"/>
    <rect fill="rgba(159, 188, 191, 0.15)" x="20" width="20" height="20" y="20"/>
  </pattern>
  <rect fill="url(#pattern)" x="0" y="0" width="100%" height="100%"/>
</svg>
<div id="accordion"></div>

              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Josefin+Slab:400,700);
@import url(https://fonts.googleapis.com/css?family=Maven+Pro);

$bodyBg: #3a3042;
$underLine: #ff784f;

body {
  background: $bodyBg;
  font-family: 'Maven Pro', sans-serif;
  margin: 0;
}

svg {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: -1;
  top: 0;
}

h1 {
  color: #fff;
  text-align: center;
  text-transform: uppercase;
  font-family: 'Josefin Slab', serif;
  font-size: 66px;
  margin-top: 10vh;
  letter-spacing: 10px;
}

.accordion-container {
  width: 60%;
  min-width: 500px;
  margin: 5vh auto;
  border-radius: 5px;
  background-color: #fff;
  box-shadow:-2px 1px 2px 2px #212121;
  
  div {
    border-bottom: 3px solid;
    border-color: $underLine;
    transition: border-color 0.5s ease-in;
  }
}

.answer, .summary {
  display: inline-block;
}

.answer {
  background: $bodyBg;
  color: #fff;
}

.summary {
  font-family: 'Josefin Slab', serif;
  text-transform: uppercase;
  cursor: pointer;
  line-height: 25px;
  padding: 15px;
  &:before {
    content: '>\0000a0';
  } 
}

.folding-pannel {
  display: block;
  transition: all 0.2s ease-in;
  line-height: 40px;
  border-top: 2px solid $bodyBg;
}

.active .summary {
  border-color: transparent;
  transition: border-color 0.2s ease-out;
}

.inactive .folding-pannel {
  transform-origin: 50% 0%;
  transform: perspective(250px) rotateX(-90deg);
  transition: all 0.4s ease-in-out;
  height: 0;

}
.active .folding-pannel {
  transform: perspective(350px) rotateX(0deg);
  transition: all 0.4s ease-in-out;
  height: 50px;
  line-height: 50px;
  text-indent: 40px;
}

              
            
!

JS

              
                class AccordionItem extends React.Component {
  constructor() {
    super();
    this.state = {
      active: false
    };
    this.toggle = this.toggle.bind(this);
  }
  toggle() {
    this.setState({
      active: !this.state.active,
      className: "active"
    });
  }
  render() {
    const activeClass = this.state.active ? "active" : "inactive";
    const question = this.props.details;
    return (
            <div className={activeClass} onClick={this.toggle}>
              <span className="summary">{question.summary}</span>
              <span className="folding-pannel answer">{question.answer}</span>
            </div>
    );
  }
}

class Accordion extends React.Component {
  constructor() {
    super();
    this.state = {
      questions: sampleQuestions,
    };
    this.renderQuestion = this.renderQuestion.bind(this);
  }
  renderQuestion(key) {
    return <AccordionItem key={key} index={key} details={this.state.questions[key]} />
  }
  render() {
    return(
      <div>
        <h1>What is...</h1>
        <div className="accordion-container">{Object.keys(this.state.questions).map(this.renderQuestion)} </div>
      </div>    
    )
  }
}
const sampleQuestions = {
  question1: {summary:'the capital of Canada?', answer:'Ottawa baby!!'},
  question2: {summary:'the life span of a bowhead whale?', answer:'Over 200 years!!'},
  question3: {summary:'the most visited city in the world?', answer:'London, groovy baby!!'},
  question4: {summary:'the warmest ocean?', answer:'Indian Ocean, it\'s a hottie!'},
  question5: {summary:'the one thing ron swanson hates more than lying?', answer:'Skim milk, which is water that\'s lying about being milk'}
};
ReactDOM.render(
  <Accordion />,
  document.getElementById('accordion')
);
              
            
!
999px

Console