cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

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
Loading ..................

Console