cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

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 id="mainContent" class="mainContent">
  <h1>Easy Show/Hide Using CSS</h1>
  <div id="toggleButton" class="toggleButton">Show Content</div>
</div>
<div id="toggledContent" class="toggledContent hide">This content area can contain anything - usually it is a menu of some sort.<br><br>The technique used involves adding or removing a class from the node you are looking to hide or show, respectively.</div>
            
          
!
            
              body
	{
	background: #fff;
	font-family: Helvetica;
	font-weight: 300;
	}

h1
	{
	padding: 0;
	margin: 20px 0;
	font-size: 20px;
	color: #555;
	}

.mainContent
	{
	position: absolute;
	z-index: 0;
	top: 0;
	left: 0;
	width: 100%;
	height: 480px;
	background: #fff;
	text-align: center;
	}

.toggleButton
	{
	width: 160px;
	height: 60px;
	line-height: 60px;
	margin: 0 auto;
	background: #D35400;
	color: #fff;
	border: 3px solid rgba(255, 255, 255, 0.5);
	text-align: center;
	cursor: pointer;
	user-select: none;
  text-transform: uppercase;
	}

.toggledContent
	{
	position: absolute;
	z-index: 999;
	top: 150px;
	left: 0;
	width: 200px;
	height: 300px;
	margin-left: -3px;
	padding: 10px;
	background: #8E44AD;
	color: #eee;
	border: 3px solid rgba(255, 255, 255, 0.3);
	transform: translateX(0);
	transition: all .3s ease;
	}

.toggledContent.hide
	{
	transform: translateX(-100%);
	}
            
          
!
            
              var contentHidden = true,
	$toggleButton = document.getElementById('toggleButton'),
	$toggledContent = document.getElementById('toggledContent');
	// equivalent jQuery code:
	// $toggleButton = $('#toggleButton');
	// $toggledContent = $('#toggledContent');

// jQuery equivalent: $toggledButton.click()
$toggleButton.onclick = function()
	{
	showHideContent();
	}

function showHideContent()
	{
	if (contentHidden)
		{
		$toggleButton.innerText = 'HIDE CONTENT';
		contentHidden = false;
		$toggledContent.className = "toggledContent";
		// equivalent jQuery code:
		// $toggledContent.removeClass('hide');
		}
	else
		{
		$toggleButton.innerText = 'SHOW CONTENT';
		contentHidden = true;
		$toggledContent.className = "toggledContent hide";
		// equivalent jQuery code:
		// $toggledContent.addClass('hide')
		}
	}
            
          
!
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