Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                    <nav id="site-navigation" class="main-navigation toggled">

      <button class="menu-toggle" aria-controls="primary-menu" aria-expanded="true">
              <a href="#"> Кнопка</a>     
      </button>



      <div class="center"> 
            <ul id="primary-menu" class="menu nav-menu">
              <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-914"><a href="#">На клик реагирует / тап не реагирует</a>
                <ul class="sub-menu">
                  <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-915"><a href="#">sub menu 1</a></li>
                  <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-109"><a href="#">sub menu 2</a></li>
                </ul>
             </li>
            </ul>
      </div>
    </nav>
              
            
!

CSS

              
                



.center {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 80vh;
}


ul li a {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}



ul.sub-menu {
    display: none;
}

ul.sub-menu.display-block {
    display: block;
}

              
            
!

JS

              
                /**
 * File navigation.js.
 *
 * Handles toggling the navigation menu for small screens and enables TAB key
 * navigation support for dropdown menus.
 */
( function() {
  const siteNavigation = document.getElementById( 'site-navigation' );

  // Return early if the navigation don't exist.
  if ( ! siteNavigation ) {
    return;
  }

  const button = siteNavigation.getElementsByTagName( 'button' )[ 0 ];

  // Return early if the button don't exist.
  if ( 'undefined' === typeof button ) {
    return;
  }

  const menu = siteNavigation.getElementsByTagName( 'ul' )[ 0 ];

  // Hide menu toggle button if menu is empty and return early.
  if ( 'undefined' === typeof menu ) {
    button.style.display = 'none';
    return;
  }

  if ( ! menu.classList.contains( 'nav-menu' ) ) {
    menu.classList.add( 'nav-menu' );
  }

  // Toggle the .toggled class and the aria-expanded value each time the button is clicked.
  button.addEventListener( 'click', function() {
    siteNavigation.classList.toggle( 'toggled' );

    if ( button.getAttribute( 'aria-expanded' ) === 'true' ) {
      button.setAttribute( 'aria-expanded', 'false' );
    } else {
      button.setAttribute( 'aria-expanded', 'true' );
    }
  } );

  // Remove the .toggled class and set aria-expanded to false when the user clicks outside the navigation.
  document.addEventListener( 'click', function( event ) {
    const isClickInside = siteNavigation.contains( event.target );

    if ( ! isClickInside ) {
      siteNavigation.classList.remove( 'toggled' );
      button.setAttribute( 'aria-expanded', 'false' );
    }
  } );

  // Get all the link elements within the menu.
  const links = menu.getElementsByTagName( 'a' );

  // Get all the link elements with children within the menu.
  const linksWithChildren = menu.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );

  // Toggle focus each time a menu link is focused or blurred.
  for ( const link of links ) {
    link.addEventListener( 'focus', toggleFocus, true );
    link.addEventListener( 'blur', toggleFocus, true );
  }

  // Toggle focus each time a menu link with children receive a touch event.
  for ( const link of linksWithChildren ) {
    link.addEventListener( 'touchstart', toggleFocus, false );
  }

  /**
   * Sets or removes .focus class on an element.
   */
  function toggleFocus() {
    if ( event.type === 'focus' || event.type === 'blur' ) {
      let self = this;
      // Move up through the ancestors of the current link until we hit .nav-menu.
      while ( ! self.classList.contains( 'nav-menu' ) ) {
        // On li elements toggle the class .focus.
        if ( 'li' === self.tagName.toLowerCase() ) {
          self.classList.toggle( 'focus' );
        }
        self = self.parentNode;
      }
    }

    if ( event.type === 'touchstart' ) {
      const menuItem = this.parentNode;
      event.preventDefault();
      for ( const link of menuItem.parentNode.children ) {
        if ( menuItem !== link ) {
          link.classList.remove( 'focus' );
        }
      }
      menuItem.classList.toggle( 'focus' );
    }
  }
}() );












document.querySelector('li.menu-item-has-children a').onclick = function() {
    document.querySelector('ul.sub-menu').classList.toggle('display-block');
    document.querySelector('li.menu-item-has-children a').classList.toggle('arrow-up');
}
              
            
!
999px

Console