Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

              
                
<main>
  <h1>Accordion</h1>
  <dl>
    <dt><a href="#acd1" class="currentBtn">1</a></dt>
    <dd id="acd1" class="current">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, </p>
    </dd>
    <dt><a href="#acd2">2</a></dt>
    <dd id="acd2">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
    </dd>
    <dt><a href="#acd3">3</a></dt>
    <dd id="acd3">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
    </dd>
    <dt><a href="#acd4">4</a></dt>
    <dd id="acd4">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
    </dd>
  </dl>
</main>
              
            
!

CSS

              
                
main{
	display:block;
	width:336px;
	margin:0 auto;
	line-height:2em;
	color:#FFF;
}

h1{
	text-align:center;
	font-size:16px;
	font-weight:normal;
	margin:16px 0;
	color:#47475A;
  border-bottom: solid 1px #000;
}

dt{
	float:left;
}

dd{
	float:left;
	width:240px;
	height:350px;
	overflow:hidden;
  margin-left: 0px;
}

dt a{
	text-align:center;
	display:block;
	padding:20px 0;
	width:24px;
	height:310px;
	color:#FFF;
	text-decoration:none;
}

dt a:hover{
	background:#DA7354;
}

dd p{
	padding:20px;
	width:100%;
}

dt:nth-of-type(1), dd:nth-of-type(1){
	background:#5F939A;
}

dt:nth-of-type(2), dd:nth-of-type(2){
	background:#3A6351;
}

dt:nth-of-type(3), dd:nth-of-type(3){
	background:#A0937D;
}

dt:nth-of-type(4), dd:nth-of-type(4){
	background:#A68DAD;
}
              
            
!

JS

              
                $(function(){
  // 1#acc1以外のwidthを0にする
  $('dd[id != "acd1"]').css("width", "0px");

  // 2 a をクリックしたときに~
  $("a").click(function(){
    // 3 currentBtnクラスがついていない場合~
    if(!$(this).hasClass("currentBtn")){
      // 4 今表示している dd の width を0にする
      $(".current").animate({"width" : "0px"}, 300);

      // 5 クリックされた a の href と同じ dd を展開 
      $($(this).attr("href")).animate({"width" : "240px"}, 300);

      // 6 dd についている current を削除
      $("dd").removeClass();

      // 7 展開された dd にcurrentクラスを追加
      $($(this).attr("href")).addClass("current");

      // 8 今付いている currentBtn クラスを削除
      $("a").removeClass();

      // クリックされたものに currentBtn クラスを追加
      $(this).addClass("currentBtn");
    }

    return false;
  });
});

              
            
!
999px

Console