cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div id="menu-container"></div>

<!--

In this snippet the submenu mounts and unmounts from the DOM React-style, in place of "traditional" hiding and showing with CSS.

Note how handlers to show and hide the Sumbenu are attached to onMouseEnter and onMouseLeave events. These are not browser events but cross-browser React wrappers called SyntheticEvents - you can read more about them here: https://reactjs.org/docs/events.html.

We've got onMouseLeave on the parent <li> element, because we want the submenu to stay open when we navigate over the submenu options.

Here's the same example with a slidedown animation added:
https://codepen.io/gitjul/pen/WMNEdr

-->

            
          
!
            
              /*
  Layout styles.

  I like to work on stuff that's good looking so I remixed a cool simple menu by Mike Rojas (thanks!): https://codepen.io/mikerojas87/pen/rojKb 
*/

$color-blue: #00aeef;
$color-blue-dark: #0d2035;
$submenu-width: 180px;

html {
  box-sizing: border-box;
}

*, *:before, *:after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Open Sans', sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.menu-container {
  text-align: center;
}

nav {
  ul {
    list-style: none;
    padding-left: 0;
    margin-top: 0;
    margin-bottom: 0;
  }
}

.nav {
  display: inline-block;
  margin: 2rem auto 0;
  background: $color-blue-dark;
  color: #fff;
  text-align: left;
  
  a {
    display: block;
    padding: 0 16px;
    line-height: inherit;
    cursor: pointer;
  }
}
  
.nav__menu {
  line-height: 45px;
  font-weight: 700;
  text-transform: uppercase;
}
  
.nav__menu-item {
  display: inline-block;
  position: relative;

  &:hover {
    background-color: $color-blue;

    .nav__submenu {
      display: block;
    }
  }
}
    
.nav__submenu {
  font-weight: 300;
  text-transform: none;
  display: none;
  position: absolute;
  width: $submenu-width;
  background-color: $color-blue;
}
    
.nav__submenu-item {
  &:hover {
    background: rgba(#000, 0.1);
  }
}

            
          
!
            
              class Submenu extends React.Component {
  render() {
    return (
      <ul className="nav__submenu">
        <li className="nav__submenu-item ">
          <a>Our Company</a>
        </li>
        <li className="nav__submenu-item ">
          <a>Our Team</a>
        </li>
        <li className="nav__submenu-item ">
          <a>Our Portfolio</a>
        </li>
      </ul>
    )
  }
}

class Menu extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showAboutMenu: false
    };
  }
  
  handleHover = () => {
    this.setState({ showAboutMenu: true });
  };
  
  handleLeave = () => {
    this.setState({ showAboutMenu: false });
  };
  
  render() {
    return (
      <nav className="nav">
        <ul className="nav__menu">
          <li className="nav__menu-item">
            <a>Home</a>
          </li>
          <li
            className="nav__menu-item"
            onMouseLeave={this.handleLeave}
          >
            <a onMouseEnter={this.handleHover}>
              About</a>
            { this.state.showAboutMenu && <Submenu /> }
          </li>
          <li className="nav__menu-item">
            <a>Contact</a>
          </li>
        </ul>
      </nav>
    )
  }
}

ReactDOM.render(
  <Menu />,
  document.getElementById("menu-container")
);
            
          
!
999px
Loading ..................

Console