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

              
                <nav>
    <div class="mobile-menu-icon">&#9776;</div> <!-- モバイル用メニューアイコン -->
    <ul class="menu">
        <li><a href="#">ホーム</a></li>
        <li class="dropdown">
            <a href="#" class="dropbtn">コンテンツA</a>
            <ul class="dropdown-content">
                <li><a href="#">コンテンツA-1</a></li>
                <li><a href="#">コンテンツA-2</a></li>
                <li><a href="#">コンテンツA-3</a></li>
            </ul>
        </li>
        <li class="dropdown">
            <a href="#" class="dropbtn">コンテンツB</a>
            <ul class="dropdown-content">
                <li><a href="#">コンテンツB-1</a></li>
                <li><a href="#">コンテンツB-2</a></li>
                <li><a href="#">コンテンツB-3</a></li>
            </ul>
        </li>
        <li><a href="#">お問い合わせ</a></li>
    </ul>
</nav>
              
            
!

CSS

              
                body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
}

nav {
    background-color: #333;
}

.mobile-menu-icon {
    display: none; /* デスクトップ表示時は非表示 */
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 14px 16px;
}

.menu {
    list-style-type: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: row; /* デフォルトは横並び */
}

.menu > li {
    position: relative;
}

.menu > li > a, .dropbtn {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

.menu > li > a:hover, .dropdown:hover .dropbtn {
    background-color: #111;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.dropdown-content li {
    width: 100%;
}

.dropdown-content li a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.dropdown-content li a:hover {
    background-color: #f1f1f1;
}

.dropdown:hover .dropdown-content {
    display: block;
    top: 100%;
}

/* メディアクエリ: 画面幅が768px以下の場合のスタイル */
@media screen and (max-width: 768px) {
    .menu {
        flex-direction: column; /* 縦並びに変更 */
    }

    .menu > li {
        width: 100%;
    }

    .menu > li > a, .dropbtn {
        text-align: left;
        padding: 14px;
    }

    .dropdown-content {
        position: static;
        display: block; /* 常に表示 */
        background-color: #333;
    }

    .dropdown-content li a {
        color: white;
    }

    .dropdown-content li a:hover {
        background-color: #111;
    }

    .dropdown:hover .dropdown-content {
        display: block; /* スタイルのために維持 */
    }

    .mobile-menu-icon {
        display: block; /* モバイル表示時に表示 */
    }

    .menu {
        display: none; /* モバイル表示時はメニューを非表示 */
    }

    .menu.open {
        display: block; /* モバイルメニューが開いている時に表示 */
    }
}
              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', function() {
    // モバイル用メニューアイコンのクリックイベントを設定
    var mobileMenuIcon = document.querySelector('.mobile-menu-icon');
    var menu = document.querySelector('.menu');
    var dropdowns = document.querySelectorAll('.dropdown');

    mobileMenuIcon.addEventListener('click', function() {
        menu.classList.toggle('open'); // メニューが開いているか閉じているかを切り替える

        // メニューが開いている場合、すべてのサブメニューを閉じる
        if (menu.classList.contains('open')) {
            dropdowns.forEach(function(dropdown) {
                dropdown.querySelector('.dropdown-content').style.display = 'none';
            });
        }
    });

    // サブメニューのクリックイベントを設定
    dropdowns.forEach(function(dropdown) {
        dropdown.addEventListener('click', function() {
            // メニューが開いている場合、クリックされたサブメニューの状態を切り替える
            if (menu.classList.contains('open')) {
                var dropdownContent = dropdown.querySelector('.dropdown-content');
                dropdownContent.style.display = (dropdownContent.style.display === 'none' || dropdownContent.style.display === '') ? 'block' : 'none';
            }
        });
    });
});

              
            
!
999px

Console