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

Auto Save

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="accordion">

  <div class="accordion_container">
    <div class="accordion_title js-accordion_title">アコーディオン1【一つ開けると他は閉じる】<div class="icon_wrap"><i class="icon"></i></div></div>
    <div class="accordion_inner js-accordion_inner">
      <div class="ac_inner_wraper">
        <p class="txt_a_ac">コンテンツが入ります。</p>
      </div>
    </div>
  </div>
  
  <div class="accordion_container">
    <div class="accordion_title js-accordion_title">アコーディオン2【一つ開けると他は閉じる】<div class="icon_wrap"><i class="icon"></i></div></div>
    <div class="accordion_inner js-accordion_inner">
      <div class="ac_inner_wraper">
        <p class="txt_a_ac">コンテンツが入ります。</p>
      </div>
    </div>
  </div>
  
  <div class="accordion_container">
    <div class="accordion_title js-accordion_title">アコーディオン3【一つ開けると他は閉じる】<div class="icon_wrap"><i class="icon"></i></div></div>
    <div class="accordion_inner js-accordion_inner">
      <div class="ac_inner_wraper">
        <p class="txt_a_ac">コンテンツが入ります。</p>
      </div>
    </div>
  </div>

</div>
              
            
!

CSS

              
                .accordion_container {
  max-width: 800px;
  margin: 0 auto;
}
.accordion_title {
  background-color: #daa520;
  color: #fff;
  font-size: 26px;
  font-weight: bold;
  padding: 20px 5%;
  text-align: center;
  position: relative;
  z-index: +1;
  cursor: pointer;
  transition-duration: 0.2s;
}
.accordion_container:nth-of-type(2) .accordion_title {
    background-color: #dc143c;
}
.accordion_container:nth-of-type(3) .accordion_title {
    background-color: #4682b4;
}
.accordion_title:hover {
  opacity: 0.8;
}
.icon_wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  top: 50%;
  right: 5%;
  width: 40px;
  height: 40px;
  margin-top: -20px;
  box-sizing: border-box;
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
  transform-origin: center center;
  transition-duration: 0.2s;
}
.icon {
  display: block;
  width: 18px;
  height: 18px;
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
  transform-origin: center center;
  transition-duration: 0.2s;
  position: relative;
}
.accordion_title.open 
.icon_wrap {
  -webkit-transform: rotate(-360deg);
  transform: rotate(-360deg);
}
.icon:before, .icon:after {
  display: flex;
  content: '';
  background-color: #fff;
  border-radius: 10px;
  width: 18px;
  height: 4px;
  position: absolute;
  top: 7px;
  left: 0;
  -webkit-transform: rotate(0deg);
  transform: rotate(0deg);
  transform-origin: center center;
}
.icon:before {
  width: 4px;
  height: 18px;
  top: 0;
  left: 7px;
}
.accordion_title.open 
.icon_wrap .icon:before {
  content: none;
}
.accordion_title.open 
.icon_wrap .icon:after {
  -webkit-transform: rotate(-45deg);
  transform: rotate(-45deg);
}
.accordion_inner {
  display: none;
  padding: 20px 20px;
  border-left: 2px solid #daa520;
  border-right: 2px solid #daa520;
  border-bottom: 2px solid #daa520;
  box-sizing: border-box;
}
.accordion_container:nth-of-type(2) .accordion_inner {
  border-left: 2px solid #dc143c;
  border-right: 2px solid #dc143c;
  border-bottom: 2px solid #dc143c;
}
.accordion_container:nth-of-type(3) .accordion_inner {
  border-left: 2px solid #4682b4;
  border-right: 2px solid #4682b4;
  border-bottom: 2px solid #4682b4;
}
.ac_inner_wraper {
  height: 100px;
}
 p.txt_a_ac {
  margin: 0;
}
@media screen and (max-width: 1024px) { 
  .accordion_title {
    font-size: 18px;
  }
  .icon_wrap {
    width: 30px;
    height: 30px;
    margin-top: -15px;
  }
}
@media screen and (max-width: 767px) {
  .accordion_title {
    font-size: 16px;
    text-align: left;
    padding: 15px 60px 15px 15px;
  }
}
              
            
!

JS

              
                $(function(){
  // .js-accordion_titleをクリックすると
  $('.js-accordion_title').click(function(){ 
    // クリックした次の要素を展開する処理
    $(this).next('.js-accordion_inner').slideToggle();
    // 展開するときjs-accordion_titleクラスにopenクラスを追加してアイコンを回転する処理
    $(this).toggleClass("open");
    // クリックされた.js-accordion_title以外の.js-accordion_titleに隣接する.js-accordion_innerを閉じる処理
    $('.js-accordion_title').not($(this)).next('.js-accordion_inner').slideUp();
    // 閉じられた他の.js-accordion_title要素に追加したopenクラスを外しアイコンを元に戻す処理
    $('.js-accordion_title').not($(this)).removeClass("open");
  });
});
              
            
!
999px

Console