cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="container">
  <button class="button-1">first button</button>
  <div class="hidden hidden-1"><p>hidden 1</p></div>
  <button class="button-2">second button</button>
  <div class="hidden hidden-2"><p>hidden 2</p></div>
  <button class="button-3">third button</button>
  <div class="hidden hidden-3"><p>hidden 3</p></div>
  <button class="button-4">fourth button</button>
  <div class="hidden hidden-4"><p>hidden 4</p></div>
  <button class="button-5">fifth button</button>
  <div class="hidden hidden-5"><p>hidden 5</p></div>
  <button class="button-6">sixth button</button>
  <div class="hidden hidden-6"><p>hidden 6</p></div>
</div>
<footer></footer>
<div class="tester"></div>

            
          
!
            
              
button {
  display: block;
  width: 100%;
  height: 30px;
  background-color: blue;
  color: white;
  border: none;
  border-bottom: 1px solid white;
}

.hidden {
  display: none;
  padding: 20px 0 0 0;
  width: 100%;
  height: 50px;
  background-color: lightgrey;
  transition: all 300ms ease;
  
  p {
    text-align: center;
  }
}

.show-hidden {
  display: inline-block;
}

.hidden-1 {
  height: 220px;
}

.hidden-3 {
  height: 240px;
}

.hidden-5 {
  height: 250px;
}

footer {
  width: 100%;
  height: 70px;
  background-color: red;
}

.tester {
  float: left;
}

.clear-float {
  clear: both;
}

@media screen and (min-width: 38em) {
  
  .container {
    position: relative;
  }

  .tester {
    float: none;
  }
  
  button {
    width: 30%;
  }
  
  .hidden {
    width: 70%;
    position: absolute;
    top: 0;
    right: 0;
  }
  
  .show-hidden {
    display: inline-block;
  }
}
            
          
!
            
              // Get the height of the container
var containerHeight = $('.container').height();

$('.button-1').click(function(){
  $('.hidden-1').toggleClass('show-hidden');
  if ($(".tester").css("float") == "none" ){
    // Get the height of the div to be shown
    var hiddenHeight = $('.hidden-1').height();
    // Find out if it's visible on the screen
    if ($('.hidden-1').hasClass('show-hidden') && hiddenHeight > containerHeight) {
      // Set the parent container to that height + 80px
      $('.container').height(hiddenHeight) 
    } else {
      $('.container').height(containerHeight);
    }
  }
  $('.hidden-2').removeClass('show-hidden');
  $('.hidden-3').removeClass('show-hidden');
  $('.hidden-4').removeClass('show-hidden');
  $('.hidden-5').removeClass('show-hidden');
  $('.hidden-6').removeClass('show-hidden');
})

$('.button-2').click(function(){
  $('.hidden-2').toggleClass('show-hidden');
  if ($(".tester").css("float") == "none" ){
    // Get the height of the div to be shown
    var hiddenHeight = $('.hidden-2').height();
    // Find out if it's visible on the screen
    if ($('.hidden-2').hasClass('show-hidden') && hiddenHeight > containerHeight) {
      // Set the parent container to that height + 80px
      $('.container').height(hiddenHeight) 
    } else {
      $('.container').height(containerHeight);
    }
  }
  $('.hidden-1').removeClass('show-hidden');
  $('.hidden-3').removeClass('show-hidden');
  $('.hidden-4').removeClass('show-hidden');
  $('.hidden-5').removeClass('show-hidden');
  $('.hidden-6').removeClass('show-hidden');
})

$('.button-3').click(function(){
  $('.hidden-3').toggleClass('show-hidden');
  if ($(".tester").css("float") == "none" ){
    // Get the height of the div to be shown
    var hiddenHeight = $('.hidden-3').height();
    // Find out if it's visible on the screen
    if ($('.hidden-3').hasClass('show-hidden') && hiddenHeight > containerHeight) {
      // Set the parent container to that height + 80px
      $('.container').height(hiddenHeight) 
    } else {
      $('.container').height(containerHeight);
    }
  }
  $('.hidden-1').removeClass('show-hidden');
  $('.hidden-2').removeClass('show-hidden');
  $('.hidden-4').removeClass('show-hidden');
  $('.hidden-5').removeClass('show-hidden');
  $('.hidden-6').removeClass('show-hidden');
})

$('.button-4').click(function(){
  $('.hidden-4').toggleClass('show-hidden');
  if ($(".tester").css("float") == "none" ){
    // Get the height of the div to be shown
    var hiddenHeight = $('.hidden-4').height();
    // Find out if it's visible on the screen
    if ($('.hidden-4').hasClass('show-hidden') && hiddenHeight > containerHeight) {
      // Set the parent container to that height + 80px
      $('.container').height(hiddenHeight) 
    } else {
      $('.container').height(containerHeight);
    }
  }
  $('.hidden-1').removeClass('show-hidden');
  $('.hidden-2').removeClass('show-hidden');
  $('.hidden-3').removeClass('show-hidden');
  $('.hidden-5').removeClass('show-hidden');
  $('.hidden-6').removeClass('show-hidden');
})

$('.button-5').click(function(){
  $('.hidden-5').toggleClass('show-hidden');
  if ($(".tester").css("float") == "none" ){
    // Get the height of the div to be shown
    var hiddenHeight = $('.hidden-5').height();
    // Find out if it's visible on the screen
    if ($('.hidden-5').hasClass('show-hidden') && hiddenHeight > containerHeight) {
      // Set the parent container to that height + 80px
      $('.container').height(hiddenHeight) 
    } else {
      $('.container').height(containerHeight);
    }
  }
  $('.hidden-1').removeClass('show-hidden');
  $('.hidden-2').removeClass('show-hidden');
  $('.hidden-3').removeClass('show-hidden');
  $('.hidden-4').removeClass('show-hidden');
  $('.hidden-6').removeClass('show-hidden');
})

$('.button-6').click(function(){
  $('.hidden-6').toggleClass('show-hidden');
  if ($(".tester").css("float") == "none" ){
    // Get the height of the div to be shown
    var hiddenHeight = $('.hidden-6').height();
    // Find out if it's visible on the screen
    if ($('.hidden-6').hasClass('show-hidden') && hiddenHeight > containerHeight) {
      // Set the parent container to that height + 80px
      $('.container').height(hiddenHeight) 
    } else {
      $('.container').height(containerHeight);
    }
  }
  $('.hidden-1').removeClass('show-hidden');
  $('.hidden-2').removeClass('show-hidden');
  $('.hidden-3').removeClass('show-hidden');
  $('.hidden-4').removeClass('show-hidden');
  $('.hidden-5').removeClass('show-hidden');
})
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console