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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <html>
  <head>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
  </head>
  <body>
    <main id="main">
    </main>
  </body>
</html>
              
            
!

CSS

              
                $color: #9b59b6;

html {
  height: 100%;
}

body {
  height: 100%;
  background-color: $color;
  font-family:'Raleway', sans-serif;
}

main {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}

#quote-box {
  background-color: white;
  display: flex;
  flex-direction: column;
  width: 600px;
  height: 350px;
  border-radius: 4px;
  margin: 10px;
}

#quote {
  width: 70%;
  height: 60%;
  margin: 10px auto;
  font-weight: 500;
  font-size: 1.25em;
  color: $color;
}

#author {
  align-self: flex-end;
  margin: 0 30px;
  font-weight: 100;
  color: $color;
}

#buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#tweet-quote {
  margin: 20px;
}

.fab {
  color: $color;
}

.fab:hover{
  color: lighten($color, 5%);
}

#new-quote {
  margin: 20px;
  vertical-align: middle;
}

.btn{
  background-color: $color;
  border-color: $color;
}

.btn:hover, .btn:active:focus, .btn:active, .btn:focus {
  background-color: lighten($color, 5%) !important;
  border-color: lighten($color, 5%) !important;
  box-shadow: none !important;
}

              
            
!

JS

              
                const quotes = [
{
       "quote":"Life isn’t about getting and having, it’s about giving and being.","author":"Kevin Kruse"},
{
       "quote":"Whatever the mind of man can conceive and believe, it can achieve.","author":"Napoleon Hill"},
{
       "quote":"Strive not to be a success, but rather to be of value.","author":"Albert Einstein"},
{
       "quote":"Two roads diverged in a wood, and I—I took the one less traveled by, And that has made all the difference.","author":"Robert Frost"},
{
       "quote":"I attribute my success to this: I never gave or took any excuse.","author":"Florence Nightingale"},
{
       "quote":"You miss 100% of the shots you don’t take.","author":"Wayne Gretzky"},
{
       "quote":"I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.","author":"Michael Jordan"},
{
       "quote":"The most difficult thing is the decision to act, the rest is merely tenacity.","author":"Amelia Earhart"},
{
       "quote":"Every strike brings me closer to the next home run.","author":"Babe Ruth"},
{
       "quote":"Definiteness of purpose is the starting point of all achievement.","author":"W. Clement Stone"}
  ]

class RandomQuotes extends React.Component {
  constructor(props) {
    super(props);
    this.state = { quote: '', author: ''};
    this.handleNewQuote = this.handleNewQuote.bind(this);
  }
  
  componentDidMount() {
    this.handleNewQuote();
  }
  render() {
    return (
      <div id="quote-box">
        <Quote quote={this.state.quote} />
        <Author author={this.state.author} />
        <div id="buttons">
          <div>
            <a id="tweet-quote" href="https://twitter.com/intent/tweet" style={{textDecoration: 'none'}}><i className="fab fa-twitter-square fa-3x" /></a>
          </div>
          <div>
            <button id="new-quote" className="btn btn-primary" onClick={this.handleNewQuote}>New Quote</button>
          </div>   
        </div>
      </div>
    )
  }
  
  handleNewQuote() {
    let randomIndex = Math.floor(Math.random() * 10);
    this.setState(state => ({
      quote: quotes[randomIndex].quote,
      author: quotes[randomIndex].author
    }));
  }
}

class Quote extends React.Component {
  render() {
    return (
        <div id="quote">
            <p id="text" style={{display: 'inline-block', textAlign: 'center'}}><i className="fas fa-quote-left fa-2x" style={{margin: 5}} />{this.props.quote}</p>
          </div>
    );
  }
}

class Author extends React.Component {
  render() {
    return (
      <p id="author">
        {this.props.author}
      </p>
    )
  }
}

ReactDOM.render(<RandomQuotes />, document.getElementById("main"));
              
            
!
999px

Console