Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <main class="container">
  <blockquote class="quote-container">
    <p id="quote"></p>
    <cite id="author"></cite>
  </blockquote>
  <div class="next-button-container">
    <button class="social-button" id="twitter"><i class="fa fa-twitter" aria-hidden="true"></i></button>
    <button class="social-button" id="tumblr"><i class="fa fa-tumblr" aria-hidden="true"></i></button>
    <button id="next">Next Quote</button>
  </div>
</main>
              
            
!

CSS

              
                .container
  position: absolute
  display: block
  background: whitesmoke
  width: 80%
  min-width: 400px
  max-width: 800px
  padding: 1.25em
  border-radius: 10px
  left: 50%
  top: 50%
  transform: translate(-50%, -50%)
  
.quote-container
  padding: 1em 2em
  font-size: 1.2em

#quote
  font-size: 1.2em
  text-align: left
  position: relative
  font-family: "Sanchez", serif
  &::before
    height: 1em
    width: 1em
    font-size: 3em
    position: absolute
    content: '“'
    top: -0.3em
    left: -0.45em

#author
  display: block
  font-style: italic
  text-align: right
  font-family: "Roboto", sans-serif
  
a
  color: inherit
  text-decoration: none
  &:hover
    opacity: 0.5
  
.next-button-container
  height: 3rem
  margin: 0em
  
.social-button
  border-radius: 5px
  border: none
  width: 3rem
  height: 100%
  margin: 0 0.25em
  vertical-align: middle
  color: whitesmoke
  text-align: center
  font-family: "Roboto", sans-serif

.social-button:active
  opacity: 0.5
  color: black

i.fa
  font-size: 2em

#next
  @extend .social-button
  font-size: 1.2em
  width: auto
  padding: 0 .75em
  float: right

@media only screen and (orientation: portrait)
  body
    font-size: 20pt
    
  .next-button-container
    height: 5rem
    
  .social-button
    width: 5rem
  
  #next
    width: auto
              
            
!

JS

              
                'use strict';

/** Depending on where this is being hosted, cors-anywhere may be required. */
jQuery.ajaxPrefilter(function(options) {
    if (options.crossDomain && jQuery.support.cors) {
        options.url = 'https://cors-anywhere.herokuapp.com/' + options.url;
    }
});

var quoteText = "";   /** Holds the returned quote text */
var authorText = "";  /** Holds the quote author's name */

/**
* Randomly generates a css color selection string, and applies it to the required elements.
*/
function ChangeColor() {

  var goldenRatio = 0.61803398875;
  var rand = (Math.random() + goldenRatio) % 1;
  rand = Math.floor(rand * 255);

  var color = "hsl(" + rand + ", 70%, 28%)";

  $("body").css({background:color,color:color});
  $("#next").css({background:color});
  $("#twitter, #tumblr").css({backgroundColor:color});
}

/**
* Ajax call that fetches quote data, parses the quote and author, and updates their respective containers.
*/
function FetchQuote() {
  $("#quote, #author").slideUp();

  $.ajax({
    url: "http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=",
    dataType: "json",
    cache : false,
    timeout: 5000,
    success : function(quote) {
      quoteText = $(quote[0].content).text();
      authorText = quote[0].title;
      $("#quote").html(quoteText).slideDown();
      $("#author").html($('<a></a>')
        .attr({'href': quote[0].link, 'target': '_blank'})
        .html("&mdash; "+authorText)
      ).slideDown();
    },
    error : function() {
      quoteText = "Something appears to have gone wrong. Please try again later.";
      $("#quote").html(quoteText).show();
    }
  });
}

/**
* Helper function to open up an external page.
* 
* @param {String} The page to open.
*/
function LoadSite(url) {
  window.open(url, 'Share', 'width=550, height=400, toolbar=0, scrollbars=1 ,location=0 ,statusbar=0,menubar=0, resizable=0');
}

/**
* Calls ChangeColor and hides quote text at page load, to assure a clean starting point for visitors.
*/
function InitializePage() {
  $("#quote, #author").hide();
  ChangeColor();
}


$(document).ready(function(){
  InitializePage();
  FetchQuote();

  $("#next").on("click",function(){
    ChangeColor();
    FetchQuote();
  });


  $("#twitter").on("click",function(){
    LoadSite('https://twitter.com/intent/tweet?hashtags=quotes&text=' + encodeURIComponent('"' + quoteText + '" -' + authorText));
  });

  $("#tumblr").on("click",function(){
    LoadSite('https://www.tumblr.com/widgets/share/tool?posttype=quote&tags=quotes&caption='+encodeURIComponent(authorText)+'&content=' + encodeURIComponent(quoteText)+'&canonicalUrl=https%3A%2F%2Fwww.tumblr.com%2Fbuttons&shareSource=tumblr_share_button');
  });
});
              
            
!
999px

Console