Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

              
                <div class="container">

<h3>Collapseの使い方 ボタンで開閉</h3>
<br>
<!-- 
  data-toggle : Collapseを起動させる
  data-target : ここで指定したidとボタンを紐づける
-->
<button type="button" class="btn btn-default btn-sm" data-toggle="collapse" data-target="#demo">
  ボタンで開閉
</button>

<!-- 
  id        : ボタンと紐付いたid
  .collapse : コンテンツを隠す
  .collapse.in : コンテンツを開いた状態
-->
<div id="demo" class="collapse">
  <h3>Collapseの中身</h3>
  <ul>
    <li>リスト1</li>
    <li>リスト2</li>
    <li>リスト3</li>
  </ul>
</div>

<hr style="margin: 40px 0;">
  
<h3>Collapseの使い方 開閉するメニュー</h3>
<br>
<ul>
  <li>
    <a data-toggle="collapse" href=".collapse-menu">
      テキストリンクで開閉
    </a>
    <ul class="collapse collapse-menu">
      <li><a href="#">サブメニュー</a></li>
      <li><a href="#">サブメニュー</a></li>
      <li><a href="#">サブメニュー</a></li>
    </ul>
  </li>
</ul>

<hr style="margin: 40px 0;">

<h3>Collapseの使い方 アコーディオン</h3>
<br>
<div class="panel-group" id="test" role="tablist" aria-multiselectable="true">
  <div class="panel panel-default">
    <div class="panel-heading" role="tab" id="headingOne">
      <h4 class="panel-title">
        <a role="button" data-toggle="collapse" data-parent="#test" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
          コンテンツ1のトグルボタン
        </a>
      </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
      <div class="panel-body">
        コンテンツ1
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading" role="tab" id="headingTwo">
      <h4 class="panel-title">
        <a class="collapsed" role="button" data-toggle="collapse" data-parent="#test" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
          コンテンツ2のトグルボタン
        </a>
      </h4>
    </div>
    <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
      <div class="panel-body">
        コンテンツ2
      </div>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading" role="tab" id="headingThree">
      <h4 class="panel-title">
        <a class="collapsed" role="button" data-toggle="collapse" data-parent="#test" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
          コンテンツ3のトグルボタン
        </a>
      </h4>
    </div>
    <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
      <div class="panel-body">
        コンテンツ3
      </div>
    </div>
  </div>
</div>

<hr style="margin: 40px 0;">

<h3>Collapse.jsの使い方</h3>
<br>
<a href="#" class="btn btn-default toggle-btn" data-toggle="collapse">jsで開く</a>
<div class="collapse collapse-content">
  Javascriptコンテンツ
</div>
<br>
<a href=".collapse-content2" class="btn btn-default" data-toggle="collapse">開き終わったら書き換え</a>
<div class="collapse collapse-content2">
  Javascriptコンテンツ
</div>
  
<hr style="margin: 40px 0;">

</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                //クリックしたらイベント発動
$('.toggle-btn').click(function () {
  //指定したidを閉じたり開いたり
  $('.collapse-content').collapse('toggle');
});

// 開き終わったらテキスト書き換え
$('.collapse-content2').on('shown.bs.collapse', function () {
  $(this).text('開き終わりました');
});
              
            
!
999px

Console