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="popup-open">
  <a href="javascript:popup_open();">ポップアップを表示します。</a>
</div>
<div id="popup-overlay">
  <div class="popup-window">
    <div class="popup-header">
      <h2>ポップアップの見出し</h2>
      <div class="popup-close">
        <a href="javascript:popup_close();">×</a>
      </div>
    </div>
    <div class="popup-body">
      <p>※ポップアップに表示する内容はこちらに記述します。</p>
    </div>
  </div>
</div>
              
            
!

CSS

              
                /* リンクの共通レイアウト */
a {
  text-decoration: none;
  color: #000;
}

/* ポップアップを開くの擬似ボタン */
.popup-open a {
  display: block;
  text-align: center;
  border: 1px solid #000;
  width: 250px;
  padding: 10px;
  margin: 0 auto;
}

/* ポップアップが開いた時のオーバレイ */
#popup-overlay {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.3);
}

/* ポップアップ */
.popup-window {
  width: 500px;
  height: 300px;
  background-color: #fff;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 10px;
}

/* ポップアップのヘッダー */
.popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  background-color: rgba(0, 0, 0, .1);
  border-radius: 10px 10px 0 0;
}

/* ポップアップの見出し */
.popup-header h2 {
  font-size: 16px;
  font-weight: normal;
  margin: 0;
  padding: 0;
}

/* ポップアップの内容 */
.popup-body {
  padding: 0 10px;
}

              
            
!

JS

              
                /* ページが開いた時 */
window.onload = function () {
  // ポップアップを表示しない
  popup_close();
};

/* ポップアップを開く */
function popup_open() {
  var popup = document.getElementById('popup-overlay');
  popup.style.display ="block";
}

/* ポップアップを閉じる */
function popup_close() {
  var popup = document.getElementById('popup-overlay');
  popup.style.display ="none";
}

/* クリックイベントの登録 */
addEventListener('click', overlay_popup_close);

/* タップイベントの登録 */
addEventListener('touchstart', overlay_popup_close);

/* オーバレイをクリックした時、ポップアップを閉じる */
function overlay_popup_close(e) {
  var popup = document.getElementById('popup-overlay');
  if (e.target == popup) {
    popup.style.display = 'none';
  }
}
              
            
!
999px

Console