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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>More/Less</title>
    <style>
        .shortText {
            transition: height 0.5s;
            height: 3em;
            overflow: hidden;
        }

        .shortText.small {
            -webkit-mask-image: -webkit-gradient(linear, left top,
                    left bottom, from(rgba(0, 0, 0, 1)), to(rgba(0, 0, 0, 0)));
        }

        .shortText.small span.more {
            display: none;
        }
    </style>
</head>

<body>
    <h2>Read More Read Less Button</h2>
    <p class="shortText small">Text 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet,
        nulla
        et dictum
        interdum, nisi lorem egestas vitae scel erisque enim ligula
        venenatis
        dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut
        aliquet. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis
        imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros
        non fermentum. Sed dapibus pulvinar nibh tempor porta.</p>
    <button class="moreless-btn">Read more</button>
    <p class="shortText small">Text 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet,
        nulla
        et dictum
        interdum, nisi lorem egestas vitae scelerisque enim ligula
        venenatis
        dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut
        aliquet. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis
        imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros
        non fermentum. Sed dapibus pulvinar nibh tempor porta.</p>
    <button class="moreless-btn">Read more</button>
    <p class="shortText small">Text 3 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet,
        nulla
        et dictum
        interdum, nisi lorem egestas vitae scel erisque enim ligula
        venenatis
        dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut
        aliquet. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis
        imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros
        non fermentum. Sed dapibus pulvinar nibh tempor porta.</p>
    <button class="moreless-btn">Read more</button>
    <script>
        // den aktuellen Zustand von Button und Text umschalten
        function toggleIt(btn) {
            var shorttxt = btn.previousElementSibling;
            shorttxt.classList.toggle("small");
            if (shorttxt.classList.contains("small")) {
                btn.textContent = "Read more";
                shorttxt.style.height = "3em";
            } else {
                btn.textContent = "Read less";
                shorttxt.style.height = shorttxt.scrollHeight + "px";
            }
        }
        function moreless() {
            // der Text ist das vorige Geschwisterelement des Buttons
            var shorttxt = this.previousElementSibling;
            if (!shorttxt.classList.contains('small')) {
                // der Text ist aufgeklappt: Zuklappen ohne weiter Aktionen
                toggleIt(this);
            } else {
                // der Text ist zugeklappt; vor dem Aufklappen muessen wir
                // alle anderen aufgeklappten Texte zuklappen
                for (var i = 0; i < btns.length; i++) {
                    var btn = btns[i];
                    if (!btn.previousElementSibling.classList.contains('small'))
                      toggleIt(btn);
                }
                // jetzt sind alle Texte zugeklappt und wir können
                // den aktuellen aufklappen
                toggleIt(this);
            }
        }
        var btns = document.querySelectorAll(".moreless-btn");
        for (var i = 0; i < btns.length; i++) {
            btns[i].addEventListener('click', moreless);;
        }
    </script>
</body>

</html>
            
          
!

CSS

            
              
            
          
!

JS

            
              
            
          
!
999px

Console