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

              
                <div class="main container">
  
  <div id="line">
    <div class="line"></div>
  </div>
  <div id="quotation-mark" class="text-center">
    <i class="fa fa-quote-left"></i>
  </div>
  
  
  <div id="quote-box">
    
    <div id="quote" class="text-center">
      <span></span>
    </div>
    <div id="author">
      <span></span>
    </div>
    
  </div>
  
  
  <div id="buttons">
    
    <div class="button-wrapper">
      <a href="#" target="_blank">
        <button id="tweet-button" class="btn">
          <i class="fa fa-twitter"></i>
        </button>
      </a>
    </div>
    
    <div class="button-wrapper">
      <button id="new-quote-button" class="btn">
        New quote 
        <i class="fa fa-quote-right"></i>
      </button>
    </div>
    
  </div>
 
</div>


<footer class="text-center container">
  <div class="row">
    
    <div class="col-sm-4">
      powered by 
      <a href="https://market.mashape.com/andruxnet/random-famous-quotes" target="_blank">Random&nbspFamous&nbspQuotes</a>
    </div>
    
    <div class="col-sm-4">
      coded by 
      <a href="https://freecodecamp.com/kborzecki" target="_blank">Konrad Borzęcki</a>
    </div>
    
    <div class="col-sm-4">
      inspired by 
      <a href="https://codepen.io/hezag/" target="_blank">hezag</a>
    </div>
    
  </div>
</footer>
              
            
!

CSS

              
                body {
  padding: 7% 20px;
  background: #fcfff5;
  font-family: Candara,Calibri,Segoe,Segoe UI,Optima,Arial,sans-serif;
  transition: 3s;
}

.main {
  position: relative;
  max-width: 650px;
  min-height: 356px;
  padding: 15px 30px 50px 30px;
  border-radius: 4px;
  background: #fcfff5;
}

#line {
  float: right;
  width: 90%;
  transition: 1s;
}
.line {
  width: 0px;
  margin-top:20px;
  margin-bottom: 10px;
  border: solid 2px #fcfff5;
  border-radius: 3px;
  transition: 3s;
}

#quotation-mark {
  float: left;
  width: 10%;
  margin-left: -10px;
  font-size: 30px;
  transition: 1s;
}
#quotation-mark i {
  color: #fcfff5;
  transition: 3s;
}

@media screen and (max-width: 360px) {
  #line {
    width: 80%;
  }
  #quotation-mark {
    width: 20%
  }
}

#quote-box {
  clear: both;
  margin-top: 5px;
  margin-bottom: 130px;
  color: #fcfff5;
}

#quote {
  font-size: 27px;
  transition: 3s;
}
#author {
  float: right;
  font-size: 20px;
  transition: 3s;
}

#buttons button {
  height: 45px;
  background: #fcfff5;
  color: #fcfff5;
  transition: 3s;
}

#tweet-button {
  position: absolute;
  left: 25px;
  bottom: 25px;
  margin-top: 30px; 
  transition: 3s;
}

#tweet-button i {
  font-size: 25px;
}

#new-quote-button {
  position: absolute;
  clear: both;
  right: 25px;
  bottom: 25px;
  margin-top: 30px;
  font-size: 18px;
  transition: 3s;
}

#new-quote-button i {
  margin-left: 5px;
  font-size: 14px;
}

.button-wrapper:hover {
  opacity: 0.75;
}

footer {
  max-width: 650px;
  margin-top: 10px;
  color: #fcfff5;
}
footer .row .col-sm-4 {
  padding: 0;
}
footer a, a:visited, a:active, a:hover, a:link{
  color: #fcfff5;
  font-size: 15px;
  font-weight: bold;
}

              
            
!

JS

              
                var quote = {
  txt: "",
  author: ""
};

var colorIndex;

function getQuote() {
  return $.ajax({
    url: 'https://andruxnet-random-famous-quotes.p.mashape.com/',
    type: 'GET',
    dataType: 'json',
    success: function(json) {
      quote.txt = json.quote;
      quote.author = json.author;
    },
    error: function(err) { 
      quote.txt = "Something went wrong and we couldn't get a random quote.";
      quote.author = "App Creator";
      console.log("Error: " + err.responseJSON.message);
    },
    beforeSend: function(xhr) {
      xhr.setRequestHeader("X-Mashape-Authorization", "sifBJMSJTsmshjGAdE65nuWAOObCp1eFz4MjsnCMvOMg2IEp1M");
    }
  });
};

function getColor(){
  var listOfColors = ['#e74c3c', '#2980b9', '#5c832f', '#d1a635', '#105b63', '#284907', '#8a0917', '#730046', '#9768d1', '#59472f', '#33332d'];
  
  /* making sure the colors don't repeat */
  var newColorIndex = Math.floor(Math.random() * 10);
  while(newColorIndex == colorIndex){
    newColorIndex = Math.floor(Math.random() * 10);
  }
  colorIndex = newColorIndex;
  
  return listOfColors[colorIndex];
};

function setColor(colorToSet){
  $("#quote, #author, #quotation-mark i").css('color', colorToSet);
  $(".line").css('border-color', colorToSet);
  $("body, #buttons button").css('background', colorToSet);
};

function changeColors(){
  setColor(getColor());
}; 

function showQuote(fadeOutTime, fadeInTime) {
  changeColors();
  $("#quote-box").fadeOut(fadeOutTime, function(){
    $("#quote span").html(quote.txt);
    $("#author span").html('-- ' + quote.author);
    $("#quote-box").fadeIn(fadeInTime);
  });
};

function generateTweet(){
  $("#tweet-button").parent().attr('href', 'https://twitter.com/intent/tweet?text=' + quote.txt + ' ~' + quote.author + ' %23quote');
}

$(document).ready(function(){
  
  $.when(getQuote()).then(function(){
    $(".line").css('width', '100%');
    showQuote(0, 1600); //AJAX success
    generateTweet();
  }, function(){
    $(".line").css('width', '100%');
    showQuote(0, 1600); //AJAX fail
    generateTweet();
  });
  
  
  $("#new-quote-button").on("click", function(){
    $.when(getQuote()).then(function(){
      showQuote(500, 1600); //AJAX success 
      generateTweet();
    }, function(){
      showQuote(500, 1600); //AJAX fail
      generateTweet();
    });
  });
 
});
              
            
!
999px

Console