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

              
                <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <link rel="stylesheet" href="sample.css">
    <script src="sample.js"></script>
    <title>テスト</title>
</head>
<body>
<header>
  <div class="container">
    <div class="header_left">
      <h1>プログラミングクエスト</h1>
    </div>
    <div class="header_right">
      <ul class="menu_list">
        <li class="nav_item"><a href="#" class="js-dropdown">menu1</a>
          <div class="panel js-dropdown-menu">
            <ul class="panel-inner">
              <li class="panel_item"><a href="#">ドロップメニュー</a></li>
              <li class="panel_item"><a href="#">ドロップメニュー</a></li>
              <li class="panel_item"><a href="#">ドロップメニュー</a></li>
            </ul>
          </div>
        </li>
        <li class="nav_item"><a href="#" class="js-dropdown">menu2</a>
          <div class="panel js-dropdown-menu">
            <ul class="panel-inner">
              <li class="panel_item"><a href="#">ドロップメニュー</a></li>
              <li class="panel_item"><a href="#">ドロップメニュー</a></li>
              <li class="panel_item"><a href="#">ドロップメニュー</a></li>
            </ul>
          </div>
        </li>
        <li class="nav_item"><a href="#">menu3</a></li>
        <li class="nav_item"><a href="#">menu4</a></li>

      </ul>
    </div>
  </div>
</header>
</body>
</html>

              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  padding: 0;
}

ul, li {
  list-style: none;
}

a {
  text-decoration: none;
}

.container {
  width: 1180px;
  max-width: 100%;
  margin: 0 auto;
}

header {
  background: #6bb6ff;
}

header > .container {
  display: flex;
  align-items: center;
  height: 80px;
}

header .header_left h1 {
  color: #fff;
}

header .header_right {
  margin-left: 8em;
}

header .header_right .menu_list {
  display: flex;
  justify-content: space-around;
}

header .header_right .menu_list .nav_item {
  position: relative;
}

header .header_right .menu_list .nav_item .panel {
  position: absolute;
  top: 52px;
  left: 0;
  right: 0;
  margin: auto;
  overflow: hidden;
  background: #6bb6fe;
  width: 100%;
  display: none;
}

header .header_right .menu_list .nav_item .panel .panel_item {
  display: inline-block;
  margin: 20px 0;
}

header .header_right .menu_list .nav_item .panel .panel_item a {
  color: #fff;
}

header .header_right .menu_list .nav_item {
  display: block;
  width: 150px;
  text-align: center;
}

header .header_right .menu_list .nav_item a {
  color: #fff;
}

              
            
!

JS

              
                $(function(){
  var $dropdown = $('.js-dropdown');
  var DURATION = 200; //アニメーションの速さ

  function fadeOutMenu(){
    $dropdown.removeClass('is-active')
      .next('.js-dropdown-menu')
      .stop()
      .slideUp(DURATION);
  }

  //表示を切り替える
  function toggleMenu(){
    var $self = $(this); //thisにはクリックした時の要素が入る
    //要素が.is-activeを持っていない場合
    if(!$self.hasClass('is-active')){
      fadeOutMenu();
    }
    //クリックした要素を表示させる
    $self.toggleClass('is-active')
      .next('.js-dropdown-menu')
      .stop().slideToggle(DURATION);
  }

  $dropdown.on('click', toggleMenu);
 
//別の場所をクリックすると閉じる処理
  $(document).on('click touchend', function(event) {
  if (!$(event.target).closest('body').length) {
    // ここに処理;
    fadeOutMenu();//関数呼びだし
  }
});
  });
              
            
!
999px

Console