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

Console