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

              
                <div class="conatiner">
  <h2>SlideUp and SlideDown effect with CSS Animation</h2>
  <hr/>
  <div class="mb-4">
    <button type="button" class="btn btn-secondary mr-2" data-target="slide-down">Slide Down</button>
    <button type="button" class="btn btn-info" data-target="slide-up">Slide Up</button>
  </div>
  <div class="card" data-target="slide-content">
    <div class="card-body">
      <form class="needs-validation" novalidate>
        <div class="form-group">
          <label for="exampleInputPassword1">Name</label>
          <input type="text" class="form-control" id="exampleInputPassword1" placeholder="Name" required>
          <div class="invalid-feedback">
            You must enter email before submitting.
          </div>
        </div>
        <div class="form-group">
          <label for="exampleInputEmail1">Email address</label>
          <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email" required>
          <div class="invalid-feedback">
            You must enter email before submitting.
          </div>
        </div>
        <button class="btn btn-primary" type="submit">Submit form</button>
      </form>
    </div>
  </div>
</div>
              
            
!

CSS

              
                $slide-content-height: 250px;

html,
body {
  padding: 30px;
}

[data-target="slide-content"] {
  height: 0;
  overflow: hidden;
  visibility: hidden;
}

.slide-down {
  animation: slide-down 0.3s linear both;
}

.slide-up {
  animation: slide-up 0.3s linear both;
}

@keyframes slide-down {
  0% {
    visibility: hidden;
    height: 0;
  }

  95% {
    visibility: visible;
    height: $slide-content-height;
  }

  /* Set height to 'auto' after animation for spacing showing form-invalid feedback message */
  100% {
    visibility: visible;
    height: auto;
  }
}

@keyframes slide-up {
  from {
    visibility: visible;
    height: $slide-content-height;
  }

  to {
    visibility: hidden;
    height: 0;
  }
}

              
            
!

JS

              
                const slideUpBtn = document.querySelector('[data-target="slide-up"]');
const slideDownBtn = document.querySelector('[data-target="slide-down"]');
const slideContent = document.querySelector('[data-target="slide-content"]');
slideDownBtn.addEventListener("click", slideDown);
slideUpBtn.addEventListener("click", slideUp);

function slideDown(e) {
  e.preventDefault();
  slideContent.classList.add("slide-down");
  slideContent.classList.remove("slide-up");
}

function slideUp(e) {
  e.preventDefault();
  slideContent.classList.add("slide-up");
  slideContent.classList.remove("slide-down");
}

/**
 * Uncessrary code just for Bootstrap Form Validation
 **/

// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
  "use strict";
  window.addEventListener(
    "load",
    function() {
      // Fetch all the forms we want to apply custom Bootstrap validation styles to
      var forms = document.getElementsByClassName("needs-validation");
      // Loop over them and prevent submission
      var validation = Array.prototype.filter.call(forms, function(form) {
        form.addEventListener(
          "submit",
          function(event) {
            if (form.checkValidity() === false) {
              event.preventDefault();
              event.stopPropagation();
            }
            form.classList.add("was-validated");
          },
          false
        );
      });
    },
    false
  );
})();

              
            
!
999px

Console