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

              
                <button id="modalOpen">モーダルを開く</button>
<!-- 追記 -->
<div class="modal-bg">
  <div class="modal">
    <div class="modal-content">
      <p>モーダルの内容</p>
      <a class="modalClose close">モーダルを閉じる</a>
      <div class="close-btn close">
        <div>
          <span></span>
          <span></span>
        </div>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                button{
  width: 300px;
  height: 50px;
  line-height: 50px;
  background-color: #2675BC;
  color: #fff;
  border: transparent;
  transition: .5s;
  cursor: pointer;
}
button:hover{
  opacity: .5;
}
.modal-bg{
  position: fixed;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, .6);
  top: 0;
  left: 0;
  z-index: 10;
  display: none;
}
.modal{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.modal-content{
  width: 400px;
  height: 200px;
  background-color: #fff;
  position: relative;
  padding: 40px;
  box-sizing: border-box;
}
.modal-content>p{
  text-align: center;
  margin-bottom: 20px;
}
.modalClose{
  display: block;
  text-align: center;
  color: #2675BC;
  transition: .5s;
}
.modalClose:hover{
  opacity: .5;
}
.close-btn{
  position: absolute;
  right: 0;
  top: -50px;
  cursor: pointer;
}
.close-btn>div{
  width: 30px;
  height: 30px;
  position: relative;
}
.close-btn>div>span{
  width: 100%;
  height: 1px;
  background-color: #fff;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}
.close-btn>div>span:first-of-type{
  transform: rotate(45deg);
}
.close-btn>div>span:last-of-type{
  transform: rotate(-45deg);
}
.modal-bg.active{
  display: block;
}
              
            
!

JS

              
                //モーダルオープン
//.modal-bgをvar modalでmodalに格納
var modal = document.querySelector('.modal-bg');

//#modalOpenをクリックしたとき
document.querySelector('#modalOpen').addEventListener('click',function(){

    //.modal-bgにactiveクラスを追加
    modal.classList.add("active");
  }
);

//モーダルクローズ
//closeクラスがついた要素をcloseBtnに格納
var closeBtn = document.querySelectorAll('.close');

//closeクラスがついた要素をforEachで一致したリストへアクセス
//fuctionの引数にbtnをセット
closeBtn.forEach(function(btn){

  //closeクラスが付いた要素をクリックしたら
  btn.onclick = function (){

    //closeクラスの親要素.modal-bgをmodalに格納
    var modal = btn.closest('.modal-bg');

    //.modal-bgのactiveクラスを外す
    modal.classList.remove("active");
  }
});
              
            
!
999px

Console