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

              
                <div id="container">
    <!-- This element's contents will be replaced with your component. -->
</div>
              
            
!

CSS

              
                .App {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
  color: black;
}

body {
  background-image: url("https://upload.wikimedia.org/wikipedia/commons/8/8a/Tree_icon_w_outline.png");
  background-repeat: no-repeat;
  background-position: right left;
  background-attachment: fixed;
}

/* Background effect. It covers the entire site */
.modal {
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Overlay effect: translucent background: black w/ partial opacity */
  z-index: 1; /* Overlay effect: positioned over other containers */
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  position: fixed; /* Fix position on the top-left corner*/
  top: 0;
  left: 0;
  overflow: auto; /* Enable scroll if needed */
  padding-top: 80px; /* Location of the content container */
}

/* Modal content */
.modal-content {
  background-color: white;
  width: 70%; /* Width in proportion to its parent container*/
  max-width: 640px; /* Max width where it stops expanding */
  height: 70%; /* Height in proportion to its parent container */
  margin: auto; /* Auto margin according to the element width */
  padding: 10px;
  border: 1px solid black;
  border-radius: 20px; /* Optional. Rounds container corners */
}

.modal-flex {
  display: flex;
  height: 100%; 
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.modal-info {
  background-color: #888;
  border: 1px solid #888;
}

/* Close button */
.close {
  color: #aaaaaa;
  float: right; /* Positioned to the right of the parent container whichever size it is */
  font-size: 25px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
}
              
            
!

JS

              
                class App extends React.PureComponent {

  state = {
    modal: false,
    modalInfo: "",
  }

  selectModal = (info = "") => {
    this.setState({
      modal: !this.state.modal,
      modalInfo: info
    })
  }


  render() {
    return (
      <div className="App">
          <p onClick={ () => this.selectModal('Modal A') }>
            Open Modal A
          </p>
          <p onClick={ () => this.selectModal('Modal B') }>
            Open Modal B
          </p>
          <Modal 
            displayModal={this.state.modal}
            modalInfo={this.state.modalInfo}
            closeModal={this.selectModal}
          />
      </div>
    );
  }
}

const Modal = props => {
  
  function displayInfo () {
    switch(props.modalInfo) {
      case 'Modal A':
        return <div className="modal-info">This is Modal A</div>
      case 'Modal B':
        return <div className="modal-info">This is Modal B</div>
      default:
        return null
    }
  }

  function closeModal (e) {
    e.stopPropagation()
    props.closeModal()
  }

  let modal = (
      <div 
      className="modal"
      onClick={ closeModal }>

        <div className="modal-content"
          onClick={ e => e.stopPropagation() }>
          
          <span 
            className="close"
            onClick={ closeModal }>&times;
          </span>

          <div className="modal-flex">
            {displayInfo()}
          </div>

        </div>

      </div>
    )

    return ( props.displayModal ? modal : null);
}

ReactDOM.render(
  <App />,
  document.getElementById('container')
);

              
            
!
999px

Console