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

              
                <!-- in a wrapping container include a div.card used to design the card  -->
<div class="container">
  <div class="card">
    <!-- in the card display a header and a div each for each option  -->

    <h2>As you evaluate your site, consider if your content is:</h2>

    <div class="card__option">
      <!-- for each option include a div in which to include the description and a span used to display a + sign, to remark the toggle-able nature of the option -->
      <div class="card__option--description">
        <!-- for the description, include a term with dt element and an illustration of said term with a dd element  -->
        <dl>
          <dt>
            perceivable
          </dt>
          <dd>
            Can people know that your cotent exists with more than one sense?
          </dd>
        </dl>
      </div>
      <span class="card__option--toggle">+</span>
    </div>

    <div class="card__option">
      <div class="card__option--description">
        <dl>
          <dt>
            understandable
          </dt>
          <dd>
            Can users take in and comprehend the information in a variety of ways?
          </dd>
        </dl>
      </div>
      <span class="card__option--toggle">+</span>
    </div>

    <div class="card__option">
      <div class="card__option--description">
        <dl>
          <dt>
            operable
          </dt>
          <dd>
            Can users interact with and navigate your website?
          </dd>
        </dl>
      </div>
      <span class="card__option--toggle">+</span>
    </div>

    <div class="card__option">
      <div class="card__option--description">
        <dl>
          <dt>
            robust
          </dt>
          <dd>
            Can people access your site using various browsers, operating systems, and assistive tools?
          </dd>
        </dl>
      </div>
      <span class="card__option--toggle">+</span>
    </div>

  </div><!-- close div.card -->

</div><!-- close div.container -->
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Open+Sans');

font-main = 'Open Sans', sans-serif
black = #252525
green = #84BC45

*
    box-sizing border-box
    margin 0
    padding 0
  
body
    min-height 100vh
    width 100%
    font-family font-main
    color black
    background green

div.container 
    display flex
    justify-content center 
    align-items center 
    min-height 100vh
    padding 1rem 2rem

    div.card 
        background #fff
        height 100vh 
        width (@height * 0.8)
        filter drop-shadow(0 1px 5px rgba(black, 0.3))
        // transition the card into view
        animation slideIn 0.3s 0.3s ease-out both
        // display the contents of the div.card in a single column layout
        display flex 
        flex-direction column

        h2, div.card__option
            // set the header and div(s) element to each cover a portion of the card 
            flex-grow 1
            padding 2rem

        h2 
            font-weight 300

        div.card__option
            // lay the div containing the text and the span containing the plus + sign in a row
            display flex 
            align-items center
            justify-content space-between
            cursor pointer
            // set transition for the change in background, prompted in the JS script
            transition all 0.3s ease

            span.card__option--toggle 
                font-size 2rem
                font-weight bold

            div.card__option--description
                dl
                    // in a dl element, dt and dd element are already displayed vertically one after the other
                    // no need to specify further layout properties (like flex)

                    dt
                        font-weight bold 
                        font-size 1.15rem
                        letter-spacing 0.05rem
                        text-transform uppercase
                        margin 0.2rem 0

                    dd 
                        font-size 1.1rem
                        // by default hide the element
                        opacity 0
                        visibility hidden
                        // set height to 0 to allow for the dt element to be centered horizontally in the parent div
                        // otherwise, the element occupies space, even if not displayed on screen
                        height 0

                        &.active
                            // define a class which transitions the dd element into view (through JS instructions)
                            opacity 1
                            visibility visible
                            height 100%
                            // set transition only to the class to prevent the transition from occurring evenly as the class is added and removed
                            // this way the transition is set only when the class is added
                            // additionally, transition opacity with a delay, giving the time to the browser to accommodate the space necessary for the dd element
                            transition visibility 0.3s ease, opacity 0.3s 0.2s ease

// define the animation for the div.card element
@keyframes slideIn 
    0% 
        opacity 0
        transform translateX(-20%)
    100% 
        opacity 1
        transform translateX(0)
              
            
!

JS

              
                // target all div containing the options
const cardOptions = document.querySelectorAll(".container .card .card__option");
// target all dd elements
const cardOptionsDescriptions = document.querySelectorAll(".container .card .card__option dl dd");
// target all span elements
const cardOptionsSpans = document.querySelectorAll(".container .card .card__option span");

// listen for a click event on each div containing each option, at which point call a function which displays the description of the clicked option 
cardOptions.forEach(cardOption => {
    cardOption.addEventListener("click", handleClick);
});

// create a function which takes as argument the (click) event and calls a function to display the correct option
function handleClick(e) {
    // pass as argument the HTML node actually clicked (this may be the div.card__option, but also one of its nested items, such as the dt, or span elements nested within)
    displayOption(e.target);
}

function displayOption(targetClick) {
    // store in a variable the clicked element, and update it in a loop in order to find the parent div.card__option
    let target = targetClick;

    // until the target is not the parent div.card__option (technically until the element contains a class of .card__option)
    while(!target.classList.contains("card__option")) {
        // update the element to go up a node
        target = target.parentNode;
    }

    // target the description element of the clicked div.card__option
    let descriptionTarget = target.querySelector("dd");

    // target the span element of the clicked div.card__option
    let spanTarget = target.querySelector("span");

    // if the dd element already has a class of active, remove it 
    // additionally reset the background of the parent container and add the plus sign + back
    if(descriptionTarget.classList.contains("active")) {
        target.style.background = "none";
        descriptionTarget.classList.remove("active");
        spanTarget.textContent = "+";
        
    }
    // otherwise call a function to remove the class of active from all options and add it exclusively to the only div.card__option 
    // additionally, style the parent container by changing its background and remove the plus sign from the nested span
    else {
        removeOptions();
        target.style.background = "rgba(0,200,0,0.2)";
        descriptionTarget.classList.add("active");
        spanTarget.textContent = " ";
    }
}

// create a function which removes the class of active from all dd elements 
// additionally reset the background of the parent container and restore the plus sign + on all span elements
function removeOptions() {
    cardOptions.forEach(cardOption => cardOption.style.background = "none");
    cardOptionsSpans.forEach(cardOptionsSpan => cardOptionsSpan.textContent = "+");
    cardOptionsDescriptions.forEach(cardOptionsDescription => cardOptionsDescription.classList.remove("active"));
}
              
            
!
999px

Console