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.

            
              <p class="description">A site menu built in React.<br/>Inspired by <a href="https://codepen.io/mican/">Michal Niewitala's</a> <a href="https://codepen.io/mican/pen/dNqPaZ">"Vertical Magic Line"</a></p>
<div id="root"></div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Rubik:300');
$bg: #34495e;
$primarycolor: #f39c12;
$white: #ecf0f1;
$font: 'Rubik';

html, body {
  background: radial-gradient($bg 0, darken($bg, 15%) 100%);
  height: 100vh;
  font-family: $font, sans-serif;
  padding: 0;
  margin: 0;
}

.description {
  color: $white;
  font-size: 22px;
  line-height: 1.4;
  padding: 50px 0;
  text-align: center;
  width: 100%;
  
  a,
  a:hover,
  a:active,
  a:focus,
  a:visited {
    color: darken($white, 15%);
    text-decoration: none;
  }
  
  a:hover {
    border-bottom: 1px solid lighten($white, 15%);
  }
}

.menu-container {
  box-shadow: 0 0px 50px hsla(0, 0, 0, 0.7);
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 350px;
}

.menu-item,
.menu-item--active {
  height: 60px;
  width: 100%;
}

.menu-item {
  align-items: center;
  color: $white;
  cursor: pointer;
  display: flex;
  font-size: 24px;
  justify-content: center;
  letter-spacing: 4px;
  text-align: center;
  
  &.active {
    box-shadow: 0 2px 3px hsla(0, 0, 0, 0.7);
  }
 
  &:nth-of-type(1) {
    background: $primarycolor;
  }
  &:nth-of-type(2) {
    background: darken($primarycolor, 5%);
  }
  &:nth-of-type(3) {
    background: darken($primarycolor, 10%);
  }
  &:nth-of-type(4) {
    background: darken($primarycolor, 15%);
  }
  &:nth-of-type(5) {
    background: darken($primarycolor, 20%);
  }
}

.menu-item--active {
  background: $primarycolor;
  border-radius: 2px !important;
  box-shadow: 0 0px 50px hsla(0, 0, 0, 0.5);
  left: 50%;
  padding: 0 7px;
  position: absolute;
  transform: translateX(-50%);
  transition: all 300ms;
  z-index: -1;
}
            
          
!
            
              ///////////////////
// App           //
///////////////////
class App extends React.Component {
  render() {
    return (
      <MenuContainer/>
    )
  }
}

///////////////////
// MenuContainer //
///////////////////
class MenuContainer extends React.Component {
  constructor(props) {
    super(props)
    
    this.state = {
      activeItem: '',
      activeItemPosition: 0,
      activeItemColor: '',
      menuItems: [
        { text: 'Home' },
        { text: 'Gallery' },
        { text: 'About' },
        { text: 'Blog' },
        { text: 'Contact' },
      ],
    }
    
    this.handleClick = this.handleClick.bind(this)
  }
  
  handleClick(activeItem) {
    return e => {
      e.preventDefault()
    
      this.setState({
        activeItem,
        activeItemPosition: document.getElementById(activeItem).offsetTop,
        activeItemColor: window.getComputedStyle(document.getElementById(activeItem)).getPropertyValue('background-color'),
      })
    }
  }
  
  render() {
    const menuItems = this.state.menuItems.map(item => <MenuItem item={ item } handleClick={ this.handleClick }/>)
    return (
      <div className='menu-container'>
        <span className='menu-item--active' style={{ top: this.state.activeItemPosition, backgroundColor: this.state.activeItemColor }}/>
        { menuItems }
      </div>
    )
  }
}

///////////////////
// MenuItem      //
///////////////////
function MenuItem(props) {
  return (
    <div 
      className='menu-item'
      id={ props.item.text }
      onClick={ props.handleClick(props.item.text) }
    >
      { props.item.text.toUpperCase() }
    </div>
  )
}




ReactDOM.render(<App/>, document.getElementById('root'))
            
          
!
999px
Loading ..................

Console