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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Random Quote Machine</title>
    <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

              
            
!

CSS

              
                $font: "Raleway", sans-serif;

body {
  font-family: $font;
  padding: 0;
}

#container {
  width: 100%;
  height: 100vh;
  padding: 150px;
  background-image: url("https://images.pexels.com/photos/207130/pexels-photo-207130.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

#inner-container {
  width: 600px;
  height: 250px;
  margin: 0px auto;
  padding: 20px;
  background-color: rgba(28, 17, 17, 0.75);
  border-radius: 10px;
  color: white;
  font-family: "Raleway", sans-serif;
  position: relative;
}

#icon-container {
  position: absolute;
  bottom: 20px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  width: 100%;
  padding: 0 20px;
}

i {
  color: white;
  font-size: 2em;
  float: left;
}

#quote {
  font-size: 1.5em;
}

#author {
  text-align: right;
}

.animated {
  transition-property: background-image;
  transition-duration: 2s;
}

@media screen and (max-width: 400px) {
  #container {
    padding: 0;
  }
  
  #inner-container {
    width: 100%;
    height: 100%;
    padding-top: 1.5em;
    padding-bottom: 1.5em;
  }
}

@media screen and (min-width: 401px) and (max-width: 600px) {
  #container {
    padding: 50px;
  }
  
}

              
            
!

JS

              
                const quotes = [
  {
    text: "Go on your path, even if you live for a day.",
    author: "Park Jimin"
  },
  {
    text: "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.",
    author: "Albert Einstein"
  },
  {
    text: "Don't cry because it's over, smile because it happened.",
    author: "Dr. Seuss"
  },
  {
    text: "Be yourself; everyone else is already taken.",
    author: "Oscar Wilde"
  },
  {
    text: "In three words I can sum up everything I've learned about life: it goes on.",
    author: " Robert Frost"
  },
  {
    text: "Darkness cannot drive out darkness: only light can do that. Hate cannot drive out hate: only love can do that.",
    author: "Martin Luther King Jr., A Testament of Hope: The Essential Writings and Speeches"
  },
  {
    text: "Live your life. It’s yours anyway. Don’t try too hard. It’s okay to lose.",
    author: "BTS, Fire"
  },
  {
    text: "There is nothing permanent except change.",
    author: "Heraclitus"
  },
  {
    text: "Learning never exhausts the mind.",
    author: "Leonardo da Vinci"
  },
  {
    text: "If you cannot do great things, do small things in a great way.",
    author: "Napoleon Hill"
  }
];

const background = [
  "https://images.pexels.com/photos/547114/pexels-photo-547114.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
  "https://images.pexels.com/photos/220067/pexels-photo-220067.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
  "https://images.pexels.com/photos/707915/pexels-photo-707915.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
  "https://images.pexels.com/photos/808465/pexels-photo-808465.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
  "https://images.pexels.com/photos/355887/pexels-photo-355887.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
  "https://images.pexels.com/photos/414667/pexels-photo-414667.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
  "https://images.pexels.com/photos/963063/pexels-photo-963063.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
  "https://images.pexels.com/photos/459301/pexels-photo-459301.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
  "https://images.pexels.com/photos/1054289/pexels-photo-1054289.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350",
  "https://images.pexels.com/photos/207135/pexels-photo-207135.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=350"
]

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      currentText: "Hardships often prepare ordinary people for an extraordinary destiny.",
      currentAuthor: "C.S. Lewis"
    }
    this.changeQuote = this.changeQuote.bind(this);
  }
  changeQuote() {
    let index = Math.floor(Math.random()*9)
    let imgUrl = "url(" + this.props.bg[index] + ")"
    this.setState({
      currentText: this.props.quoteList[index]["text"]
    })
    this.setState({
      currentAuthor: this.props.quoteList[index]["author"]
    })
    container.style.backgroundImage = imgUrl;
  }
  render() {
      let textToTweet = this.state.currentText + " - " + this.state.currentAuthor;
      let makeLink = (input) => {
        let regex = /\s/gi
        let tweet = input.replace(regex, "%20");
        return tweet;
      };
    let link = "https://twitter.com/home?status=" + makeLink(textToTweet);
    console.log(link)
    return(
      <div id="container" className="animated">
        <div id="inner-container">
          <div id="text-container">
            <p id="quote"><i className="fas fa-quote-left"></i> {this.state.currentText}</p>
            <p id="author">- {this.state.currentAuthor} </p>
          </div>
          <div id="icon-container" className="row">
            <a href={link} target="_blank"><i className="fab fa-twitter-square"></i></a>
            <button type="button" className="btn btn-light " onClick={this.changeQuote} id="changeColor">New Quote</button>
          </div>
        </div>
      </div>
    );
  }
}

class Nest extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return(
      <App quoteList={quotes} bg={background} />
    );
  }
}

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

Console