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

              
                <div class="quotebox">
  <div class="content">
    <div id="tekst">
      <blockquote id="quote"></blockquote>
      <cite id="author"></cite>
    </div>
    <div class="buttons">
      <div id="some">
        <a href="#" id="twitter" target="_blank"><i class="fa fa-twitter"></i></a>
      </div>
      <div id="new">
        <a href="#">New quote</a>
      </div>
    </div>
  </div>
</div>

              
            
!

CSS

              
                body {
  min-height: 100vh;
  background-color: blue;
  transition: background-color 1.5s;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: Verdana, Geneva, sans-serif;
}

.quotebox {
  background-color: white;
  min-width: 400px;
  max-width: 50%;
  border-radius: 3px;
}

.content {
  margin: 1em 1.7em 1.7em 1.7em;
  display: flex;
  flex-flow: column nowrap;
  justify-content: space-between;
}

blockquote {
  font-size: 1.3em;
  line-height: 1.2em;
  margin: 1em 1em 1em 0;
}

cite {
  float: right;
  font-size: 1em;
  margin: 0.7em 0 1em 0;
}

cite::before {content: "- "}

.buttons {
  font-size: 1.5em;
  display: flex;
  justify-content: space-between;
}

.buttons div a {
  background-color: blue;
  transition: background-color 1s;
  color: white;
  margin: 0px 7px 0px 0px;
  padding: 7px;
  display: flex;
  width: 30px;
  height: 25px;
  text-decoration: none;
  justify-content: center;
  align-items: center;
  border-radius: 3px;
}

#some {
  display: flex;
}

#new {
  font-size: 0.6em;
}

#new a {
  width: 92px;
  margin: 0;
}

.buttons a:hover {font-size: 1.1em; transform: scale(1.1);}

div {color: black; transition: color 1s;}
              
            
!

JS

              
                var quotes = [
  { quote: "God never said that the journey would be easy, but He did say that the arrival would be worthwhile.",
    author: "Max Lucado"
  },
  { quote: "Glory is fleeting, but obscurity is forever.",
    author: "Napoleon Bonaparte"
  },
  { quote: "If you can’t fly, then run, If you can’t run, then walk, If you can’t walk, then crawl, but whatever you do, you have to keep moving forward.",
    author: "Martin Luther King Jr"
  },
  { quote: "Victory goes to the player who makes the next-to-last mistake.",
    author: "Chessmaster Savielly Grigorievitch Tartakower (1887-1956)"
  },
  { quote: "A lie gets halfway around the world before the truth has a chance to get its pants on.",
    author: "Sir Winston Churchill"
  }
]

var outq = document.getElementById("quote");
var outa = document.getElementById("author");

document.addEventListener('DOMContentLoaded', function() {
  var createrand = function(range) {
    var newrand = Math.floor(Math.random() * range);
    // check if running first time
    if (typeof randnr === "undefined" || randnr === null) {
      return newrand;
    } else {
      // avoid two same quotes in a row
      if (newrand === randnr) {
        while (newrand === randnr) {
          newrand = Math.floor(Math.random() * range);
        }
      }
    }
    return newrand;
  }
  
  var animColors = function() {
    // create random hex colors, curtesy of Paul Irish
    // https://www.paulirish.com/2009/random-hex-color-code-snippets/
    var mainColor = '#'+Math.floor(Math.random()*16777215).toString(16);

    var priElements = document.querySelectorAll("div");
    var secElements = document.querySelectorAll("div a");
    
    for (var i=0; i<priElements.length; i++) {
      priElements[i].style.color = mainColor;
    }
    
    for (var i=0; i<secElements.length; i++) {
      secElements[i].style.backgroundColor = mainColor;
    }
    document.body.style.backgroundColor = mainColor;
    
  }
  
  var newQuote = function() {
    randnr = createrand(quotes.length);
    var q = quotes[randnr].quote;
    var aut = quotes[randnr].author;
    outq.textContent = q;
    outa.textContent = aut;
    tweetItReady();
  }
  
  var doNew = function() {
    animColors();
    newQuote();
  }
  
  var timer = setInterval(doNew, 10000);
  
  document.getElementById("new").addEventListener("click", function() {
    doNew();
    clearInterval(timer);
    timer = setInterval(doNew, 10000);
  });
  
  var tweetItReady = function() {
    var twitter = document.getElementById("twitter");
    twitter.href = 
      // I love template literals
      `http://twitter.com/home?status=${outq.textContent} 
      ${outa.textContent} @sveinarneroed`;
  };
  
  // get quote of the day from theysaidso API on page load,
  // fallback to quote from array if error reaching API
  var qod = function() {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "https://quotes.rest/qod.json", true);
    xhr.onreadystatechange = function() {
      if(xhr.readyState === XMLHttpRequest.DONE) {
        if (xhr.status === 200) {
          var res = xhr.responseText;
          var json = JSON.parse(res);
          outq.textContent = json.contents.quotes[0].quote;
          outa.textContent = json.contents.quotes[0].author;
          tweetItReady();
        } else {
          newQuote();
        }
      }
    };
    xhr.send();
  };

  qod();
  animColors();

});

              
            
!
999px

Console