css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id = "main"></div>
            
          
!
            
              body {
  background: #36413E;
  background: linear-gradient(to top right, rgb(15,15,15), rgb(50,50,50)) fixed no-repeat;
  color: #D7D6D6;
  text-align: center;
}

h1 {
  font-size: 50px;
  font-weight: normal;
  color: #FF5E33;
}

// Styling for control buttons:
.controlWrapper {
  .allBtn {
    margin-top: -25px;
    margin-bottom: 15px;
  }
  button {
    width: 175px;
    font-size: 22px;
    padding: 10px;
    margin: 5px;
    font-family: 'Rubik';
    border: none;
    border-Radius: 3px;
    box-shadow: none;
    transition: color 150ms ease-in, background 100ms ease-in;
  }
  button:hover {
    cursor: pointer;
    background: #06FF96 !important;
    color: #FF5E33;
    transition: color 150ms ease-in, background 100ms ease-in;
  }
  button:focus {
    outline: none;
  }
  .controls {
    max-width: 750px;
    margin: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
    hr {
      margin-top: 25px;
      margin-bottom: -45px;
      width: 85vw;
      border: 1px solid #F8F4A6;
    }
  }
}

// Container for transition divs:
.transitionsContainer {
  padding: 50px;
  color: rgb(20,20,20);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: row;
  flex-wrap: wrap;
}
.transitionBox {
  border: 1px solid #F8F4A6;
  transition: border 150ms ease-in;
}
.transitionBox:hover {
  border: 1px solid #FF5E33;
  transition: border 150ms ease-in;
}

// Fade Transition:
.fadeDiv-enter {
  opacity: 0.01;
}
.fadeDiv-enter.fadeDiv-enter-active {
  opacity: 1;
  transition: opacity 1000ms ease-in;
}
.fadeDiv-leave {
  opacity: 1;
}
.fadeDiv-leave.fadeDiv-leave-active {
  opacity: 0.01;
  transition: opacity 1000ms ease-in;
}

// Slide In/Out Transition:
.slideInDiv-enter {
  transform: translate3d(600%, 0, 0);
}
.slideInDiv-enter.slideInDiv-enter-active {
  transform: translate3d(0, 0, 0);
  transition: transform 800ms ease-in;
}
.slideInDiv-leave {
  transform: translate3d(0, 0, 0);
}
.slideInDiv-leave.slideInDiv-leave-active {
  transform: translate3d(600%, 0, 0);
  transition: transform 800ms ease-in;
}

// Slide Up/Down Transition:
.slideUpDiv-enter {
  transform: translate3d(0, -300%, 0);
}
.slideUpDiv-enter.slideUpDiv-enter-active {
  transform: translate3d(0, 0, 0);
  transition: transform 800ms ease-in;
}
.slideUpDiv-leave {
  transform: translate3d(0, 0, 0);
}
.slideUpDiv-leave.slideUpDiv-leave-active {
  transform: translate3d(0, -300%, 0);
  transition: transform 800ms ease-in;
}

// Slide Up/Down Transition:
.sliderDiv-enter {
  transform: translate3d(-1000%, -300%, 0);
}
.sliderDiv-enter.sliderDiv-enter-active {
  transform: translate3d(0, 0, 0);
  transition: transform 1000ms ease-in;
}
.sliderDiv-leave {
  transform: translate3d(0, 0, 0);
}
.sliderDiv-leave.sliderDiv-leave-active {
  transform: translate3d(-1000%, 300%, 0);
  transition: transform 1000ms ease-in;
}


// Height In/Out Transition:
.heightInDiv-enter {
  max-height: 0;
}
.heightInDiv-enter.heightInDiv-enter-active {
  max-height: 150px;
  transition: max-height 1000ms ease-in;
}
.heightInDiv-leave {
  max-height: 150px;
}
.heightInDiv-leave.heightInDiv-leave-active {
  max-height: 0;
  transition: max-height 1000ms ease-in;
}

// Width In/Out Transition:
.widthInDiv-enter {
  max-width: 0;
}
.widthInDiv-enter.widthInDiv-enter-active {
  max-width: 150px;
  transition: max-width 750ms ease-in;
}
.widthInDiv-leave {
  max-width: 150px;
}
.widthInDiv-leave.widthInDiv-leave-active {
  max-width: 0;
  transition: max-width 1000ms ease-in;
}
// Width In/Out Inner Text Transition:
.widthInTextBefore {
  color: rgba(0,0,0,0);
  transition: color 250ms ease-out;
}
.widthInTextAfter {
  color: #000000;
  transition: color 2500ms ease-out;
  transition-delay: .75s;
}

// Size In/Out Transition:
.sizeInDiv-enter {
  max-width: 0;
  max-height: 0;
}
.sizeInDiv-enter.sizeInDiv-enter-active {
  max-width: 150px;
  max-height: 150px;
  transition: max-width 650ms ease-in, max-height 750ms ease-in;
}
.sizeInDiv-leave {
  max-width: 150px;
  max-height: 150px;
}
.sizeInDiv-leave.sizeInDiv-leave-active {
  max-width: 0;
  max-height: 0;
  transition: max-width 1000ms ease-in, max-height 1000ms ease-in;
}
// Size In/Out Inner Text Transition:
.sizeTextBefore {
  color: rgba(0,0,0,0);
  transition: color 250ms linear;
}
.sizeTextAfter {
  color: #F0EBD8;
  transition: color 2500ms linear;
  transition-delay: .75s;
}

// Rotate In/Out Transition:
.rotateInDiv-enter {
  transform: rotate(720deg);
  opacity: 0.01;
}
.rotateInDiv-enter.rotateInDiv-enter-active {
  transform: rotate(0deg);
  opacity: 1;
  transition: transform 1000ms ease-in, opacity 1000ms ease-in;
}
.rotateInDiv-leave {
  transform: rotate(0deg);
  opacity: 1;
}
.rotateInDiv-leave.rotateInDiv-leave-active {
  transform: rotate(720deg);
  opacity: 0.01;
  transition: transform 1500ms ease-in, opacity 1500ms ease-in;
}
// Rotate In/Out Inner Text Transition:
.rotateTextBefore {
  color: rgba(0,0,0,0);
  transition: color 1000ms ease-in;
}
.rotateTextAfter {
  color: #FF3F00;
  transition: color 1000ms ease-in;
  transition-delay: .05s;
}

            
          
!
            
              
// Some global style definitions:
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;

var transitionDivStyle = {
  'width': '150px',
  'height': '150px',
  'padding': '10px',
  'margin': '25px',
  'display': 'flex',
  'justifyContent': 'center',
  'alignItems': 'center',
  'fontSize': '22px',
  'fontFamily': 'Avenir',
  'fontWeight': 'bold',
  'cursor': 'pointer',
  'borderRadius': '5px',
  'color': 'rgb(25,25,25)'
};

var btnActive = { 'background': '#06FF96' };
var btnInactive = { 'background': '#FDD692' };

// Root Component:
class Root extends React.Component {
  constructor() {
    super();
    this.state = {
      toggleAll: true,
      fade: true,
      slideIn: true,
      slideUp: true,
      slider: true,
      height: true,
      width: false,
      size: false,
      rotate: false
    };
    
    this.toggleAll = this.toggleAll.bind(this);
    this.toggleFade = this.toggleFade.bind(this);
    this.toggleSlideIn = this.toggleSlideIn.bind(this);
    this.toggleSlideUp = this.toggleSlideUp.bind(this);
    this.toggleSlider = this.toggleSlider.bind(this);
    this.toggleHeightIn = this.toggleHeightIn.bind(this);
    this.toggleWidthIn = this.toggleWidthIn.bind(this);
    this.toggleSize = this.toggleSize.bind(this);
    this.toggleRotate = this.toggleRotate.bind(this);
    
  }
  toggleAll() {
    if (!this.state.toggleAll) {
      
      this.setState({
        toggleAll: true,
        fade: true,
        slideIn: true,
        slideUp: true,
        slider: true,
        height: true,
      });
      
      if (!this.state.width) {
        this.toggleWidthIn();
      }
      
      if (!this.state.size) {
        this.toggleSize();
      }
      
      if (!this.state.rotate) {
        this.toggleRotate();
      }
      
    }
    else {
      
      this.setState({
        toggleAll: false,
        fade: false,
        slideIn: false,
        slideUp: false,
        slider: false,
        height: false,
        rotate: false,
      });
      
      if (this.state.width) {
        this.toggleWidthIn();
      }
      
      if (this.state.size) {
        this.toggleSize();
      }
      
      if (this.state.rotate) {
        this.toggleRotate();
      }
      
    }
  }
  toggleFade() {
    if (!this.state.fade) {
      this.setState({
        fade: true
      });
    }
    else {
      this.setState({
        fade: false
      });
    }
  }
  toggleSlideIn() {
    if (!this.state.slideIn) {
      this.setState({
        slideIn: true
      });
    }
    else {
      this.setState({
        slideIn: false
      });
    }
  }
  toggleSlideUp() {
    if (!this.state.slideUp) {
      this.setState({
        slideUp: true
      });
    }
    else {
      this.setState({
        slideUp: false
      });
    }
  }
  toggleSlider() {
    if (!this.state.slider) {
      this.setState({
        slider: true
      });
    }
    else {
      this.setState({
        slider: false
      });
    }
  }
  toggleHeightIn() {
    if (!this.state.height) {
      this.setState({
        height: true
      });
    }
    else {
      this.setState({
        height: false
      });
    }
  }
  toggleWidthIn() {
    if (!this.state.width) {
      this.setState({
        width: true
      });
      setTimeout(function() {
        var element = document.getElementById('widthInId');
        element.classList.add('widthInTextAfter');
      }, 15);
    }
    else {
      this.setState({
        width: false
      });
      var element = document.getElementById('widthInId');
      element.className = element.className.replace('widthInTextAfter', '');
    }
  }
  toggleSize() {
    if (!this.state.size) {
      this.setState({
        size: true
      });
      setTimeout(function() {
        var element = document.getElementById('sizeDivId');
        element.classList.add('sizeTextAfter');
      }, 15);
    }
    else {
      this.setState({
        size: false
      });
      var element = document.getElementById('sizeDivId');
      element.className = element.className.replace('sizeTextAfter', '');
    }
  }
  toggleRotate() {
    if (!this.state.rotate) {
      this.setState({
        rotate: true
      });
      setTimeout(function() {
        var element = document.getElementById('rotateDivId');
        element.classList.add('rotateTextAfter');
      }, 15);
    }
    else {
      this.setState({
        rotate: false
      });
      var element = document.getElementById('rotateDivId');
      element.className = element.className.replace('rotateTextAfter', '');
    }
  }  
  componentWillMount() {
    this.toggleWidthIn();
    this.toggleSize();
    this.toggleRotate();
  };
  render() {
    return (
      <div>
        <h1>React CSS Transition Demos</h1>
        <Controller
          toggleAllBtns = {this.state.toggleAll}
          fade = {this.state.fade}
          slideIn = {this.state.slideIn}
          slideUp = {this.state.slideUp}
          slider = {this.state.slider}
          height = {this.state.height}
          width = {this.state.width}
          size = {this.state.size}
          rotate = {this.state.rotate}
          toggleAll = {this.toggleAll}
          toggleFade = {this.toggleFade}
          toggleSlideIn = {this.toggleSlideIn}
          toggleSlideUp = {this.toggleSlideUp}
          toggleSlider = {this.toggleSlider}
          toggleHeightIn = {this.toggleHeightIn}
          toggleWidthIn = {this.toggleWidthIn}
          toggleSize = {this.toggleSize}
          toggleRotate = {this.toggleRotate} />          
        <div className = "transitionsContainer">
          <FadeIn fade = {this.state.fade} toggleFade = {this.toggleFade} />
          <SlideIn slideIn = {this.state.slideIn} toggleSlideIn = {this.toggleSlideIn} />
          <SlideUp slideUp = {this.state.slideUp} toggleSlideUp = {this.toggleSlideUp} />
          <Slider slider = {this.state.slider} toggleSlider = {this.toggleSlider} />
          <HeightIn height = {this.state.height} toggleHeightIn = {this.toggleHeightIn} />
          <WidthIn width = {this.state.width} toggleWidthIn = {this.toggleWidthIn} />
          <SizeIn size = {this.state.size} toggleSize = {this.toggleSize} />
          <RotateIn rotate = {this.state.rotate} toggleRotate = {this.toggleRotate} />
        </div>
      </div>
    );
  }
};

// Component for button controls:
class Controller extends React.Component {
  render() {
    var toggleAllText = "Toggle All On";
    var toggleAllBtnStyle = btnInactive;
    if (this.props.toggleAllBtns) {
      toggleAllBtnStyle = btnActive;
      toggleAllText = "Toggle All Off";
    }     
    var fadeText = "Fade In";
    var fadeBtnStyle = btnInactive;
    if (this.props.fade) {
      fadeBtnStyle = btnActive;
      fadeText = "Fade Out";
    }
    var slideInText = "Slide In Left";
    var slideInBtnStyle = btnInactive;
    if (this.props.slideIn) {
      slideInBtnStyle = btnActive;
      slideInText = "Slide Out Right";
    }
    var slideUpText = "Slide In Down";
    var slideUpBtnStyle = btnInactive;
    if (this.props.slideUp) {
      slideUpBtnStyle = btnActive;
      slideUpText = "Slide Out Up";
    }
    var sliderText = "Slider In";
    var sliderBtnStyle = btnInactive;
    if (this.props.slider) {
      sliderBtnStyle = btnActive;
      sliderText = "Slider Out";
    }
    var heightText = "Height In";
    var heightBtnStyle = btnInactive;
    if (this.props.height) {
      heightBtnStyle = btnActive;
      heightText = "Height Out";
    }
    var widthText = "Width In";
    var widthBtnStyle = btnInactive;
    if (this.props.width) {
      widthBtnStyle = btnActive;
      widthText = "Width Out";
    }
    var sizeText = "Size In";
    var sizeBtnStyle = btnInactive;
    if (this.props.size) {
      sizeBtnStyle = btnActive;
      sizeText = "Size Out";
    }
    var rotateText = "Rotate In";
    var rotateBtnStyle = btnInactive;
    if (this.props.rotate) {
      rotateBtnStyle = btnActive;
      rotateText = "Rotate Out";
    }    
    return (
      <div className = "controlWrapper">
        <button style = {toggleAllBtnStyle} onClick = {this.props.toggleAll} className = "allBtn">{toggleAllText}</button>
        <div className = "controls">
          <button style = {fadeBtnStyle} onClick = {this.props.toggleFade}>{fadeText}</button>
          <button style = {slideInBtnStyle} onClick = {this.props.toggleSlideIn}>{slideInText}</button>
          <button style = {slideUpBtnStyle} onClick = {this.props.toggleSlideUp}>{slideUpText}</button>
          <button style = {sliderBtnStyle} onClick = {this.props.toggleSlider}>{sliderText}</button>
          <button style = {heightBtnStyle} onClick = {this.props.toggleHeightIn}>{heightText}</button>
          <button style = {widthBtnStyle} onClick = {this.props.toggleWidthIn}>{widthText}</button>
          <button style = {sizeBtnStyle} onClick = {this.props.toggleSize}>{sizeText}</button>
          <button style = {rotateBtnStyle} onClick = {this.props.toggleRotate}>{rotateText}</button>          
          <hr />
        </div>
      </div>
    );
  }
};

// Fade In Component:
class FadeIn extends React.Component {
  render() {
    var background = {
      'background': '#c03546'
    }
    var component;
    if (this.props.fade) {
      component = (
        <div style = {Object.assign({}, transitionDivStyle, background)} onClick = {this.props.toggleFade} className = "transitionBox">
          <p>This div fades in and out</p>
        </div>
      )
    }
    return (
      <ReactCSSTransitionGroup
        transitionName = 'fadeDiv'
        transitionEnterTimeout = {1000}
        transitionLeaveTimeout = {1000}>
        {component}
      </ReactCSSTransitionGroup>
    );
  }
};

// Slide In Component:
class SlideIn extends React.Component {
  render() {
    var background = {
      'background': '#004e66'
    }
    var component;
    if (this.props.slideIn) {
      component = (
        <div style = {Object.assign({}, transitionDivStyle, background)} onClick = {this.props.toggleSlideIn} className = "transitionBox">
          <p>This div slides in and out</p>
        </div>
      )
    }
    return (
      <ReactCSSTransitionGroup
        transitionName = 'slideInDiv'
        transitionEnterTimeout = {800}
        transitionLeaveTimeout = {800}>
        {component}
      </ReactCSSTransitionGroup>
    );
  }
};

// Slide Up Component:
class SlideUp extends React.Component {
  render() {
    var background = {
      'background': '#f8ca00'
    }
    var component;
    if (this.props.slideUp) {
      component = (
        <div style = {Object.assign({}, transitionDivStyle, background)} onClick = {this.props.toggleSlideUp} className = "transitionBox">
          <p>This div slides up and down</p>
        </div>
      )
    }
    return (
      <ReactCSSTransitionGroup
        transitionName = 'slideUpDiv'
        transitionEnterTimeout = {800}
        transitionLeaveTimeout = {800}>
        {component}
      </ReactCSSTransitionGroup>
    );
  }
};

// Slider Component:
class Slider extends React.Component {
  render() {
    var background = {
      'background': '#348AA7'
    }
    var component;
    if (this.props.slider) {
      component = (
        <div style = {Object.assign({}, transitionDivStyle, background)} onClick = {this.props.toggleSlider} className = "transitionBox">
          <p>This div slides around</p>
        </div>
      )
    }
    return (
      <ReactCSSTransitionGroup
        transitionName = 'sliderDiv'
        transitionEnterTimeout = {1000}
        transitionLeaveTimeout = {1000}>
        {component}
      </ReactCSSTransitionGroup>
    );
  }
};

// Height In/Out Component:
class HeightIn extends React.Component {
  render() {
    var background = {
      'background': '#BF4E30'
    }
    var component;
    if (this.props.height) {
      component = (
        <div style = {Object.assign({}, transitionDivStyle, background)} onClick = {this.props.toggleHeightIn} className = "transitionBox">
          <p>This div grows and squishes</p>
        </div>
      )
    }
    return (
      <ReactCSSTransitionGroup
        transitionName = 'heightInDiv'
        transitionEnterTimeout = {1000}
        transitionLeaveTimeout = {1000}>
        {component}
      </ReactCSSTransitionGroup>
    );
  }
};

// Width In/Out Component:
class WidthIn extends React.Component {
  render() {
    var background = {
      'background': '#ed317f'
    }
    var component;
    if (this.props.width) {
      component = (
        <div style = {Object.assign({}, transitionDivStyle, background)} onClick = {this.props.toggleWidthIn} className = "transitionBox">
          <p id = 'widthInId' className = 'widthInTextBefore'>This div expands and squeezes (with fade in text!)</p>
        </div>
      );      
    }
    return (
      <ReactCSSTransitionGroup
        transitionName = 'widthInDiv'
        transitionEnterTimeout = {750}
        transitionLeaveTimeout = {1000}>
        {component}
      </ReactCSSTransitionGroup>
    );
  }
};

// Size In/Out Component:
class SizeIn extends React.Component {
  render() {
    var background = {
      'background': '#1D2D44'
    }
    var component;
    if (this.props.size) {
      component = (
        <div style = {Object.assign({}, transitionDivStyle, background)} onClick = {this.props.toggleSize} className = "transitionBox">
          <p id = "sizeDivId" className = "sizeTextBefore">This div expands and contracts (with fade in text!)</p>
        </div>
      );      
    }
    return (
      <ReactCSSTransitionGroup
        transitionName = 'sizeInDiv'
        transitionEnterTimeout = {750}
        transitionLeaveTimeout = {1000}>
        {component}
      </ReactCSSTransitionGroup>
    );
  }
};

// Size In/Out Component:
class RotateIn extends React.Component {
  render() {
    var background = {
      'background': '#5B3758'
    }
    var component;
    if (this.props.rotate) {
      component = (
        <div style = {Object.assign({}, transitionDivStyle, background)} onClick = {this.props.toggleRotate} className = "transitionBox">
          <p id = "rotateDivId" className = "rotateTextBefore">This div rotates!</p>
        </div>
      );      
    }
    return (
      <ReactCSSTransitionGroup
        transitionName = 'rotateInDiv'
        transitionEnterTimeout = {1000}
        transitionLeaveTimeout = {1500}>
        {component}
      </ReactCSSTransitionGroup>
    );
  }
};

ReactDOM.render(<Root />, document.getElementById('main'));
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console