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 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

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

              
                <main class="card">
  <div class="hero">
    <img src="https://raw.githubusercontent.com/ArtemPonomarenko/FAQ-Accordion/main/images/illustration-woman-online-mobile.svg" alt="section image" class="img">
  </div>

  <h2 class="title">FAQ</h2>

  <div class="acc-container">

    <button class="acc-btn">What is the definition of a will?</button>
    <div class="acc-content">
      <p>
        It is a dead giveaway.
      </p>
    </div>

    <button class="acc-btn">
      What happens to chemists when they die?
    </button>
    <div class="acc-content">
      <p>
        We barium [bury them].
      </p>
    </div>

    <button class="acc-btn">
      Why does the leopard find it difficult to hide and stalk?
    </button>
    <div class="acc-content">
      <p>
        Because he is spotted always.
      </p>
    </div>

    <button class="acc-btn">
      What kind of key opens a banana?
    </button>
    <div class="acc-content">
      <p>
        A monkey. 🙈
      </p>
    </div>

    <button class="acc-btn">
      Where does a tree store it's stuff?
    </button>
    <div class="acc-content">
      <p>
        In it's Trunk.
      </p>
    </div>

    <button class="acc-btn">
      What dog is known for its punctuality?
    </button>
    <div class="acc-content">
      <p>
        The watch-dog 🐕
      </p>
    </div>

    <button class="acc-btn">
      Name a thing that has four wheels and flies?
    </button>
    <div class="acc-content">
      <p>
        The garbage truck, of course.
      </p>
    </div>

    <button class="acc-btn">
      Why was everyone so tired on the First of April?
    </button>
    <div class="acc-content">
      <p>
        Because they had just completed a March of 31 days.
      </p>
    </div>

  </div>
</main>

<p class="credit">
  Built with ❤️ by <a href="https://twitter.com/tutuldevs">Tutul</a>. <br />
  Design inspired by <a href="https://www.frontendmentor.io/challenges/faq-accordion-card-XlyjD0Oam">FrontEnd Mentor</a>.
  See my other <a href="https://all-js.netlify.app">JavaScript projects</a>.
</p>
              
            
!

CSS

              
                * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
html {
    font-family: sans-serif;
    font-size: 10px;
}
body {
    width: 100%;
    min-height: 100vh;
    font-size: 1.6rem;
    line-height: 140%;
    background-color: #f3f6f6;
    opacity: 0.3;
    opacity: 1;
    display: grid;
    place-items: center;
}
.card {
    background: #fff;
    color: #333;
    margin: 15rem auto;
    width: 90%;
    max-width: 1200px;
    min-height: 30rem;
    border-radius: 2rem;
}

.hero {
    display: flex;
    justify-content: center;
    transform: translateY(-55%);
}
.hero .img {
    filter: drop-shadow(0rem 1.5rem rgba(0,0,0,0.1));
    transition: 0.3s ease-out;
}
.card:hover .img {
    filter: drop-shadow(0rem 2.5rem rgba(0,0,0,0.1));
}

.title {
    text-align: center;
    font-size: 5rem;
    padding: 1rem;
}

.acc-container {
    padding: 4rem 2rem;
}
.acc-btn {
    width: 100%;
    padding: 1.6rem 2rem;
    font-size: 1.6rem;
    cursor: pointer;
    background: inherit;
    border: none;
    outline: none;
    text-align: left;
    transition: all 0.5s linear;
}
.acc-btn:after {
    content: "\27A4";
    color: #fa8d0c;
    float: right;
    transition: all 0.3s linear;
}
.acc-btn.is-open:after {
    transform: rotate(90deg);
}
.acc-btn:hover, .acc-btn.is-open {
    color: #000;
    font-weight: bold;
}

.acc-content {
    max-height: 0;
    color: rgba(0,0,0,0.75);
    font-size: 1.5rem;
    margin: 0 2rem;
    padding-left: 1rem;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
    border-bottom: 1px solid #ccc;
}

.credit {
    text-align: center;
    padding: 1rem;
}
.credit a {
    text-decoration: wavy underline;
    color: dodgerblue;
}
              
            
!

JS

              
                const btns = document.querySelectorAll(".acc-btn");

// fn
function accordion() {
  // this = the btn | icon & bg changed
  this.classList.toggle("is-open");

  // the acc-content
  const content = this.nextElementSibling;

  // IF open, close | else open
  if (content.style.maxHeight) content.style.maxHeight = null;
  else content.style.maxHeight = content.scrollHeight + "px";
}

// event
btns.forEach((el) => el.addEventListener("click", accordion));

/*
   
       Jokes are from > 
        https://chartcons.com/100-funny-trick-questions-answers/
        Background image from > 
        https://www.magicpattern.design/tools/css-backgrounds
   
*/

              
            
!
999px

Console