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>
    <header id="header" class="wrapper">
      <h1 class="site-title">
        <a href="index.html"><img src="https://i.pinimg.com/564x/63/fb/20/63fb204f34531dcf3aed7ed61381fae8.jpg" alt=""></a>
      </h1>

      <nav id="navi">
        <ul class="nav-menu">
          <li><a href="">PRODUCTS</a></li>
          <li><a href="">ABOUT</a></li>
          <li><a href="">COMPANY</a></li>
          <li><a href="">CONTACT</a>
<!--             <a href="mailto:xxxxx@xxx.xxx.com?subject=お問い合わせ">CONTACT</a>            -->
          </li>
        </ul>
      </nav>
      
      <div id="mask"></div>

      <div class="toggle_btn">
        <span></span>
        <span></span>
      </div>

      
    </header>

    <main>
      <div id="top" class="wrapper">
      </div>
    </main>


  </body>
</html>
              
            
!

CSS

              
                @charset "UTF-8";
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 100%;
}

body {
  color: #333;
  font-size: 1rem;
}
a {
  color: #333;
  text-decoration: none;
  transition: all 0.5s;
}
a:hover {
  opacity: 0.7;
}
img {
  max-width: 100%;
}
li {
  list-style: none;
}

/*
コンテンツ幅を設定するための共通クラス
*/
.wrapper {
  width: 80%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 40px;
}


/*-------------------------------------------
ヘッダー
-------------------------------------------*/
/*
「position: fixed;」でヘッダーを固定し、「z-index: 10;」で前面に表示
※他のコンテンツでpositionをrelative、absolute、fixedのいずれかに
設定している場合は、z-indexの数値が大きい方が前面に表示される
*/
#header {
/*   width: 100%; */
  height: 80px;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  left: 0;
  right: 0;
  z-index: 10;
  position: relative;
}

/*
ハンバーガーメニュー
メニューが閉じている時は、「left: -300px;」で画面左に隠し、
「opacity: 0;」で非表示にしている
*/
#navi {
  position: fixed;
  top: 0;
  left: -300px;
  width: 300px;
  color: #fff;
  padding: 36px 50px;
  transition: all 0.5s;
  z-index: 20;
  opacity: 0;
}
#navi a {
  color: #fff;
}
#navi li {
  margin-bottom: 14px;
}
.site-title img {
  width: 100px;
}



/*
ハンバーガーメニュー
メニューが開いている時は、「left: 0;」「opacity: 1;」で
画面左に表示する
*/
.open #navi {
  left: 10%;
  opacity: 1;
}

/*
ハンバーガーメニューの位置の設定(ポイント:position:relative,z-indexに大きめの数字,transitionはspanに)
*/
.toggle_btn {
  width: 30px;
  height: 30px;
  position: relative;
  transition: all 0.5s;
  cursor: pointer;
  z-index: 20;
}
/*
ハンバーガーメニューの線の設定(メニューが閉じている時)
*/
.toggle_btn span {
  display: block;
  position: absolute;
  width: 30px;
  height: 2px;
  background-color: #333;
  border-radius: 4px;
  transition: all 0.5s;
}
/*
1本目の線の位置を設定
*/
.toggle_btn span:nth-child(1) {
  top: 10px;
}
/*
2本目の線の位置を設定
*/
.toggle_btn span:nth-child(2) {
  bottom: 10px;
}
/*
ハンバーガーメニューの線の設定(メニューが開いている時 .openがつく)
線の色を白に変更
*/
.open .toggle_btn span {
  background-color: #fff;
}
/*
1本目の線を-45度回転 nth-child()で指定する
*/
.open .toggle_btn span:nth-child(1) {
  -webkit-transform: translateY(4px) rotate(-225deg);
  transform: translateY(4px) rotate(-225deg); /* ちょっと多めに回転させてる */
}
/*
2本目の線を45度回転
*/
.open .toggle_btn span:nth-child(2) {
  -webkit-transform: translateY(-4px) rotate(225deg);
  transform: translateY(-4px) rotate(225deg);
}
/* 黒背景は最初は非表示 */
#mask {
	background: #000;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 20;
	visibility: hidden;
	opacity: 0;
	transition: opacity 1s ease, visibility 1s ease;
}
/*
メニューを開いている時は、全体を黒背景にする
*/
.open #mask {
  opacity: 1
  transition: opacity .6s ease, visibility .6s ease;
  visibility: visible;
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: .9;
  z-index: 10; /* 2本線より低い数字 */
  cursor: pointer;
}




              
            
!

JS

              
                $(function(){
  /*=================================================
  ハンバーガーメニュー
  ===================================================*/
  // ハンバーガーメニューのクリックイベント
  $('.toggle_btn').on('click', function() {
    // #headerにopenクラスが存在する場合
    if ($('#header').hasClass('open')) {
      // openクラスを削除
      // openクラスを削除すると、openクラスのCSSがはずれるため、
      // メニューが非表示になる
      $('#header').removeClass('open');

    // #headerにopenクラスが存在しない場合
    } else {
      // openクラスを追加
      // openクラスを追加すると、openクラスのCSSが適応されるため、
      // メニューが表示される
      $('#header').addClass('open');
    }
  });

  // メニューが表示されている時に画面をどこでもクリックした場合
  $('#mask').on('click', function() {
    // openクラスを削除して、メニューを閉じる
    $('#header').removeClass('open');
  });
});
              
            
!
999px

Console