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

              
                <body>
<button id="modal-button">タップして開く</button>
</body>

              
            
!

CSS

              
                body {
  background-size: cover;
  background-color: #efefef;
}
.modal {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal .inner {
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.9);
  margin: 10px;
  display: block;
  width: 960px;
  height: 540px;
  border-radius: 5px;
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
  padding: 20px;
  text-align: center;
  background-color: rgba(255, 255, 255, 0.9);
  max-width: 600px;
  max-height: 400px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  color: #333;
  font-size: 1.5rem;
  animation: fadeInAnimation 200ms ease-out;
}

button{
    background: #666;
    color; #fff;
    text-decoration: none;
    color: #fff;
    text-align: center;
    border: none;
    border-radius: 4px;
    display: inline-block;
    height: 72px;
    line-height: 72px;
    padding: 0 32px;
    text-transform: uppercase;
    font-size: 2rem;
    cursor: pointer;
    transition: background-color 0.2s;
}
button:hover{
  background: #666;
  opacity: 0.8;
}

@keyframes fadeInAnimation {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

              
            
!

JS

              
                //クリックした時の処理
document.querySelector('#modal-button').addEventListener('click', openModalWindow);

//モーダルウィンドウを表示する
function openModalWindow(){

  //モーダルを生成する→新しいタグを生成
  const modalElement = document.createElement('div');
  
  // 作ったdivの中にcss→modalを付与する
  modalElement.classList.add('modal');

  //モーダルウィンドウの中身を作る
  //新しいdivタグを生成する
  const innerElement = document.createElement('div');
  //作ったdivの中にcss→innerを付与する
  innerElement.classList.add('inner');
  innerElement.innerHTML =
  `<p>モーダルの中身です</p>
  <p>テキストや画像も入るよ</p>`
  ;
  //モーダルの中身に要素を配置する
  modalElement.appendChild(innerElement);
  //body要素にモーダルを配置する
  document.body.appendChild(modalElement);


  //中身をクリックしたらモーダルウインドウを削除する
  innerElement.addEventListener('click',() => {
    closeModalWindow(modalElement);
  });
}

//モーダルウインドウを閉じる
function closeModalWindow(modalElement){
  document.body.removeChild(modalElement);
}


              
            
!
999px

Console