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

              
                <!DOCTYPE html>
<html>
    <head>
            <meta charset="utf-8">
            <title>Mythical Accordion Mini-Project</title>
            <link rel="stylesheet" type="text/css" href = "../css/style.css">
            <link href="https://fonts.googleapis.com/css?family=Oswald:300,700|Pacifico" rel="stylesheet">
    </head>
    <body>

        <header>
            <h1>The Mythical Accordion</h1>
            <p>Everything cool has either wings or a tail.</p>
        </header>

        <div class="main-content">
            <dt class="description-title">Dragon <span class="expand-collapse">&#10133;</span></dt>
            <dd class="description">This is quite obviously the best of all the creatures. My one true love.
            <p> Examples include Smaug (The Hobbit), Tintaglia (The Liveship Traders) and Spyro (Spyro video games).</p></dd>
            <dt class="description-title">Mermaid<span class="expand-collapse">&#10133;</span></dt>
            <dd class="description">Mermaids in stories are either super cute or super scary. They're popular in YA at the moment.
            <p>Examples include Ariel (The Little Mermaid), Sh'eenaz (The Witcher).</p></dd>
            <dt class="description-title">Siren<span class="expand-collapse">&#10133;</span></dt>
            <dd class="description">Sirens are not the same as mermaids. They are totally badass and lure men to their deaths.
            <p> Sirens don't usually get names.... sad face.</p></dd>
            <dt class="description-title">Pegasus<span class="expand-collapse">&#10133;</span></dt>
            <dd class="description">Better than a horse.
            <p>I think these appear in Greek mythology?</p></dd>


        </div>

        <footer>
            Created by Ellie
            <div class="images">
                <a href="https://twitter.com/elliempatten"><img alt="Twitter logo"src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAh1BMVEX///8AAAAeHh78/Pz5+fnY2NjU1NT09PT29vYkJCTa2trIyMji4uLPz8/u7u7r6+tGRkZXV1eMjIyOjo5+fn5ra2u5ubnk5OSZmZkwMDBLS0saGhqwsLB2dnYNDQ2mpqZbW1s+Pj6urq43NzdwcHAuLi6enp4/Pz9kZGRZWVlJSUl7e3sLCwte2NoYAAAJPUlEQVR4nO2de5+qLBDHM2+lWXk3L9nVOmd7/6/vcbfds2YioAzq5+H7Z5nyC4GZYYDZTCAQCAQCgUAgEAgEAoFAIPjfohjmKY9Kijw1VX3o4jBF0VfRVnrj5lm6MnTZGKCEprd8l/ck8czVxGtzbUZHlLwnOy/Y0NxRhipqJ9bBR9Ku7wv/tCK84SIoxlTli8CfE+greRyikOCG61O2PI6oDjUf2fwaNMYB7n6Lwi7/sJxH0clwSN7PCvt7+/sX7R6flyG+5V+zKkX9/SNHlVPeOD+XIC5wSVsyI/Ti0UGgJHlNvaq8MbOfC+aI8dOUbBVUUY2V10lfif9WzrWVx7/fnxBPLC+xNWBVFbR7V4GSFJvVOylq+mIt2OvmJ1pfX3KTaMaI0hNxTv/dSM292q1Q/a3/9e3W4CTw3EegJC3dz7soZnTf1nvjDFGFxvcjr1y6G61LJ/rCI84y+7h876uuJuKZzr9LOEi0rn0FookQz9R/2/0SvC0af+EE3lEGerVdHC1YgaEPJxBd9qJ6WYx6lZmgO6ji9eeBtFvX2cuFW0CJckroSnQBbXFrtZZxhJNo9Bwn2ijQpnVQ/1+XUBJlwEboLtDPPb1fDiQxhRPo1ByrsDIoNDb+E4Q3tYYT+FKD+irfSkVFbdOrs48Agh1g/eje/S3t2gj80tixK07UqtEMTlyEhd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uNxfMQYw76qVzZn8bZj3Qd7V48FJxvGvAwyQmzpz+DroZH/ekrb5etFyKZ75Kov5+8lKSq/tb/3YDVIoELe8MlIyDS+k54vKCr07iZJFA4TZ/plkcdQo8d+lw07XfYP1f3DfviYb/22A215U3atF5YbY+3uzmmwMDYK3To5MZMYxi0rzKGC2BgUw0y9flV5znJzyK6TAD00AqfTQPmIvVRdrUfU9tAour4KHJv8lU22XhDqOsdkJlZ8tk0/Pi/nzSzP8d3LLfYRF4FAIBAIBAKBQCAQCAQCgWDE/AceIcSv/K+IswAAAABJRU5ErkJggg==" ></a>
                <a href="https://github.com/elliempatten"><img alt="GitHub logo" src="https://image.freepik.com/free-icon/github-logo-black-shape_318-52922.jpg" ></a>
        </div>
    </footer>
        <script src="accordion.js"></script>
    </body>
</html>
              
            
!

CSS

              
                $heading-color: rgb(125, 175, 190);
$description-title-color: rgb(255, 255, 255);
$default-text-color: rgb(53, 53, 63);
$background-color-2: rgb(55, 154, 184);
$background-color-3: rgb(125, 175, 190);
$round-border: 10px;
$text-left-padding: 10px;
$title-font: 'Pacifico', cursive;
$body-font: 'Oswald', sans-serif;

body {
    box-sizing: border-box;
    font-family: $body-font;
}

header {
    text-align: center;
    margin-bottom: 90px;
    font-size: 20px;
}

h1 {
    font-family: $title-font;
    font-size: 50px;
    color: $heading-color;
    margin-bottom: 0;
}

.main-content {
    margin: 40px 30% 40px 30%;
    width: 40%;

    .description-title {
        font-size: 26px;
        background-color: $background-color-2;
        color: $description-title-color;
        padding-left: $text-left-padding;
        line-height: 55px;
        border-radius: $round-border;
        transition: 0.3s;
        margin-top: 2px;
        margin-bottom: 2px;
        &:hover {
            background-color: $background-color-3;
            cursor: pointer;
        }
         
    }
    .expand-collapse{
            float: right;
            margin-right: 8px;
        }
    .description {
        font-size: 18px;
        color: $default-text-color;
        max-height: 0;
        overflow: hidden;
        margin-left: 0px;
        padding-left: $text-left-padding;
        transition: max-height 0.2s ease-out;
        p {
            margin-top: 4px;
        }
}
}

footer {
    text-align: center;
    font-size: 20px;
    bottom: 0px;
    margin-bottom: 20px;
    width: 100%;
    margin-top: 100px;
    img {
        margin-top: 5px;
        height: 50px;
    }
    
}
              
            
!

JS

              
                
if (document.readyState !== 'loading') {
    console.log("ready!");
    ready();
} else {
    document.addEventListener('DOMContentLoaded', ready);
}

function ready() {
    var accordion = document.getElementsByTagName("dt");

    for (var i = 0; i<accordion.length; i++){
        accordion[i].addEventListener('click', function(){
            accordionClick(event);
        
        });
    }
}

var accordionClick = (eventHappened) => {
    console.log(eventHappened);
    var targetClicked =event.target;
    console.log(targetClicked);
    var classClicked = targetClicked.classList;
    console.log("target clicked: " + targetClicked);
    console.log(classClicked[0]);
    while ((classClicked[0] !="description-title")){
        console.log("parent element: " + targetClicked.parentElement);
        targetClicked = targetClicked.parentElement;
        classClicked = targetClicked.classList;
        console.log("target clicked while in loop:" + targetClicked);
        console.log("class clicked while in loop: " + classClicked);
    }
    var description = targetClicked.nextElementSibling;
    console.log(description);
    var expander = targetClicked.children[0];
    if (description.style.maxHeight){
        description.style.maxHeight = null;
        expander.innerHTML = "&#10133;"
        
    }
    else {
        var allDescriptions = document.getElementsByTagName("dd");
        for (var i = 0; i < allDescriptions.length; i++){
            console.log("current description: " + allDescriptions[i]);
            if (allDescriptions[i].style.maxHeight){
                console.log("there is a description already open");
                allDescriptions[i].style.maxHeight = null;
                allDescriptions[i].previousElementSibling.children[0].innerHTML = "&#10133;"
            }
        }
        description.style.maxHeight = description.scrollHeight + "px";
        expander.innerHTML = "&#10134;";
        
    }
}
              
            
!
999px

Console