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

              
                <head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <!--==============レイアウトを制御する独自のCSSを読み込み===============-->
  <link rel="stylesheet" type="text/css" href="https://dl.dropbox.com/s/saz7ehm66llopzw/reset.css?dl=0">
</head>

<body>
  <div id="container">
    <header id="header">
      <h1>Logo</h1>

      <nav>
        <ul>
          <li><a href="#">Top</a></li>
          <li class="has-child"><a href="#">About</a>
            <ul>

              <li><a href="#">
                  <dl>
                    <dt><img src="https://dl.dropbox.com/s/p5217elx7wmekyk/01.jpg?dl=0" alt=""></dt>
                    <dd>About Top</dd>
                  </dl>
                </a></li>
              <li><a href="#">
                  <dl>
                    <dt><img src="https://dl.dropbox.com/s/snye4ydng8xe8cg/02.jpg?dl=0" alt=""></dt>
                    <dd>About-1</dd>
                  </dl>
                </a></li>
              <li><a href="#">
                  <dl>
                    <dt><img src="https://dl.dropbox.com/s/il4yq6wvdn7o6qx/03.jpg?dl=0" alt=""></dt>
                    <dd>About-2</dd>
                  </dl>
                </a></li>
              <li><a href="#">
                  <dl>
                    <dt><img src="https://dl.dropbox.com/s/az6q8xot8wd5cdi/04.jpg?dl=0" alt=""></dt>
                    <dd>About-3</dd>
                  </dl>
                </a></li>
              <li><a href="#">
                  <dl>
                    <dt><img src="https://dl.dropbox.com/s/f4nhgtv8j0kyxh5/05.jpg?dl=0" alt=""></dt>
                    <dd>About-4</dd>
                  </dl>
                </a></li>

            </ul>
          </li>

          <li class="has-child"><a href="#">Service</a>
            <ul>

              <li><a href="#">
                  <dl>
                    <dt><img src="https://dl.dropbox.com/s/ymba9sg9t43yfca/06.jpg?dl=0" alt=""></dt>
                    <dd>Service Top</dd>
                  </dl>
                </a></li>
              <li><a href="#">
                  <dl>
                    <dt><img src="https://dl.dropbox.com/s/woq6b5hxytkd2qf/07.jpg?dl=0" alt=""></dt>
                    <dd>Service-1</dd>
                  </dl>
                </a></li>
              <li><a href="#">
                  <dl>
                    <dt><img src="https://dl.dropbox.com/s/mtnv3j5stm1u0hx/08.jpg?dl=0" alt=""></dt>
                    <dd>Service-2</dd>
                  </dl>
                </a></li>
              <li><a href="#">
                  <dl>
                    <dt><img src="https://dl.dropbox.com/s/cy5jjqoc3xdhyhc/09.jpg?dl=0" alt=""></dt>
                    <dd>Service-3</dd>
                  </dl>
                </a></li>
              <li><a href="#">
                  <dl>
                    <dt><img src="https://dl.dropbox.com/s/s9eys7ype7ny7vo/10.jpg?dl=0" alt=""></dt>
                    <dd>Service-4</dd>
                  </dl>
                </a></li>

            </ul>
          </li>
          <li><a href="#">Blog</a></li>
        </ul>
      </nav>

    </header>

    <main id="main-area">
      <section id="area-1">
        <h2>Area 1</h2>
        <p>テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。</p>
        <p>テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。</p>
        <p>テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。</p>
        <p>テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。テキストが入ります。</p>
        <!--/area1-->
      </section>
      <!--/main-->
    </main>
    <!--/container-->
  </div>

  <footer id="footer">
    <small>&copy; copyright.</small>
  </footer>
  <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
</body>
              
            
!

CSS

              
                @charset "utf-8";

/*========= ドロップダウンのためのCSS ===============*/

/*==ナビゲーション全体の設定*/
nav ul {
  list-style: none;
  text-align: center;
}

/*ナビゲーションのリンク設定*/
nav ul li a {
  /*矢印の基点にするためrelativeを指定*/
  position: relative;
  display: block;
  text-decoration: none;
  color: #000;
  padding: 20px 15px;
  transition: all 0.3s;
}

nav ul li a:hover {
  color: #666;
}

nav ul li li a {
  padding: 15px;
}

/*==矢印の設定*/

/*2階層目を持つliの矢印の設定*/

nav ul li.has-child > a::before {
  content: "";
  position: absolute;
  right: 20px;
  top: 28px;
  width: 6px;
  height: 6px;
  border-top: 2px solid #999;
  border-right: 2px solid #999;
  transform: rotate(45deg);
}

/*==2階層目以降の画像設定*/

nav ul li.has-child img {
  max-width: 100%;
  height: auto;
  transition: all 0.5s;
  vertical-align: bottom;
}

/*hoverしたら画像拡大*/
nav ul li.has-child img:hover {
  transform: scale(1.2);
}

nav ul li.has-child dt {
  overflow: hidden;
  height: 10vh;
  margin: 0 0 10px 0;
}

/*== 2階層目の設定 */

nav li.has-child ul {
  /*絶対配置で位置を指定*/
  position: absolute;
  top: 0;
  left: 100%;
  z-index: 4;
  /*形状を指定*/
  width: 100%;
  height: 100vh;
  background: #888;
  /*はじめは非表示*/
  visibility: hidden;
  opacity: 0;
  /*アニメーション設定*/
  transition: all 0.3s;
}

/*hoverしたら表示*/
nav li.has-child:hover > ul {
  visibility: visible;
  opacity: 1;
}

/*ナビゲーションaタグの形状*/
nav li.has-child ul li a {
  color: #fff;
}

nav li.has-child ul li a:hover,
nav li.has-child ul li a:active {
  background: #3577ca;
}

/*==768px以下の形状*/
@media screen and (max-width: 768px) {
  nav {
    background: #333;
    color: #fff;
  }

  nav li.has-child ul li {
    text-align: left;
  }

  nav li.has-child ul li dl {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  nav li.has-child ul li dt {
    width: 30%;
    height: auto;
    margin: 0;
  }

  nav li.has-child ul li dd {
    width: 64%;
  }

  nav li.has-child ul {
    position: relative;
    left: 0;
    top: 0;
    width: 100%;
    height: auto;
    visibility: visible; /*JSで制御するため一旦表示*/
    opacity: 1; /*JSで制御するため一旦表示*/
    display: none; /*JSのslidetoggleで表示させるため非表示に*/
    transition: none; /*JSで制御するためCSSのアニメーションを切る*/
  }

  nav ul li a {
    border-bottom: 1px solid #ccc;
    color: #fff;
  }

  nav ul li li a {
    padding: 0;
  }

  /*矢印の位置と向き*/

  nav ul li.has-child a::before {
    transform: rotate(135deg);
    left: 20px;
    right: inherit;
  }

  nav ul li.has-child.active a::before {
    transform: rotate(-45deg);
  }
}

/*========= レイアウトのためのCSS ===============*/

#container {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

#header {
  width: 17%;
  background: #f3f3f3;
  position: relative; /*2階層目表示の基準*/
}

#main-area {
  width: 78%;
}

@media screen and (max-width: 768px) {
  #header,
  #main-area {
    width: 100%;
  }
}

h1 {
  font-size: 2rem;
  text-align: center;
  text-transform: uppercase;
  padding: 20px;
}

h2 {
  font-size: 1.2rem;
  text-align: center;
  margin: 0 0 30px 0;
}

p {
  margin-top: 20px;
}

small {
  background: #333;
  color: #fff;
  display: block;
  text-align: center;
  padding: 20px;
}

section {
  padding: 30px;
}

              
            
!

JS

              
                //ドロップダウンの設定を関数でまとめる
function mediaQueriesWin() {
  var width = $(window).width();
  if (width <= 768) {
    //横幅が768px以下の場合
    $(".has-child>a").off("click"); //has-childクラスがついたaタグのonイベントを複数登録を避ける為offにして一旦初期状態へ
    $(".has-child>a").on("click", function () {
      //has-childクラスがついたaタグをクリックしたら
      var parentElem = $(this).parent(); // aタグから見た親要素の<li>を取得し
      $(parentElem).toggleClass("active"); //矢印方向を変えるためのクラス名を付与して
      $(parentElem).children("ul").stop().slideToggle(500); //liの子要素のスライドを開閉させる※数字が大きくなるほどゆっくり開く
      return false; //リンクの無効化
    });
  } else {
    //横幅が768px以上の場合
    $(".has-child>a").off("click"); //has-childクラスがついたaタグのonイベントをoff(無効)にし
    $(".has-child>a").removeClass("active"); //activeクラスを削除
    $(".has-child").children("ul").css("display", ""); //スライドトグルで動作したdisplayも無効化にする
  }
}

// ページがリサイズされたら動かしたい場合の記述
$(window).resize(function () {
  mediaQueriesWin(); /* ドロップダウンの関数を呼ぶ*/
});

// ページが読み込まれたらすぐに動かしたい場合の記述
$(window).on("load", function () {
  mediaQueriesWin(); /* ドロップダウンの関数を呼ぶ*/
});

              
            
!
999px

Console