cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->

	<title>Random Quote Machine</title>

	<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet">
	<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
	<link href="css/style.css" rel="stylesheet">

	<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<div class="flexbox-container">
	<div id="quotes">
		<div id="text">
			<i class="fa fa-quote-left fa-3x" aria-hidden="true"></i>
			<p id="quote-text"></p><br />
			<p id="quote-author"></p>
			<i class="fa fa-quote-right fa-3x" aria-hidden="true"></i><br />
		</div>

		<div id="buttons">
			<button class="button" id="new-quote-button" onclick="getQuote()">New Quote</button>
			<button class="button" id="tweet-button" onclick="shareTweet()"><i class="fa fa-twitter" aria-hidden="true"></i> Share on Twitter</button>
		</div>
	</div>
</div>

<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="js/index.js"></script>

</body>

</html>
            
          
!
            
              /********** GLOBAL STYLES **********/

/* Testing purposes */
* {
	border: 0px solid red;
}

html, body {
	height: 100%;
	margin: 0;
}

body {
	transition:background 1s;

	-webkit-font-smoothing: antialiased;
	text-rendering: optimizelegibility;
}

/********** QUOTES BOX **********/

.flexbox-container {
	height: 100%;

	display: flex;
	display: -ms-flexbox;
	display: -webkit-flex;

	justify-content: center;
	align-items: center;
	-ms-flex-align: center;
	-webkit-align-items: center;
	-webkit-box-align: center;
}

#quotes {
	width: 500px;
	height: 300px;
	padding: 20px;
	border: 1px solid black;
	border-radius: 8px;
	transition:background 1s;
	font-family: 'Raleway', sans-serif;
	font-size: 25px;
}

.fa, p {
	display: inline;
}

p {
	padding: 20px;
}

.button {
    border: none;
    color: white;
    padding: 15px 32px;
    width: 246px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    border-radius: 8px;
    -webkit-transition-duration: 0.4s; /* Safari */
    transition-duration: 0.4s;
    cursor: pointer;
}

#text {
	height: 250px;
}
            
          
!
            
              // Colors: [Background, Quote box Background, Text, Buttons, Buttons Hover]
// Color Combinations from: https://designschool.canva.com/blog/100-color-combinations/
// http://www.hexcolortool.com - Used to generate 10% lighter color for button hover
var colors = [
	["#444C5C","#CE5A57","#78A5A3","#E1B16A", "#FBCB84"],
	["#90AFC5","#336B87","#2A3132","#763626", "#905040"], // Subdued & Professional
	["#46211A","#693D3D","#BA5536","#A43820", "#BE523A"], // Dark & Earthy
	["#505160","#68829E","#AEBD38","#598234", "#739C4E"], // Crisp & Dramatic
	["#2E4600","#486B00","#A2C523","#7D4427", "#975E41"], // Outdoorsy & Natural
	["#375E97","#FB6542","#FFBB00","#3F681C", "#598236"], // Primary Colors With a Vibrant Twist
	["#F4CC70","#DE7A22","#20948B","#6AB187", "#84CBA1"], // Surf & Turf
	["#8D230F","#1E434C","#9B4F0F","#C99E10", "#E3B82A"], // Autumn in Vermont
	["#011A27","#063852","#F0810F","#E6DF44", "#FFF95E"], // Day & Night
	["#0F1B07","#ffffff","#5C821A","#C6D166", "#E0EB80"]  // Modern & Crisp
];

var colorIndex = 0;

window.onload = function WindowLoad(event) {
    getQuote();
}

function getQuote() {
	// Get a quote from Famous Quotes API on MashApe
	$.ajax({
	    url: 'https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile
	    type: 'GET', // The HTTP Method, can be GET POST PUT DELETE etc
	    data: {}, // Additional parameters here
	    dataType: 'json',
	    success: function(data) {
	       	document.getElementById("quote-text").innerHTML = data.quote; 
	       	document.getElementById("quote-author").innerHTML = data.author; 
	    },
	    error: function(err) { 
	    	alert("Error: " + err.status + ". " + err.responseText);	
	    },
	    beforeSend: function(xhr) {
	    xhr.setRequestHeader("X-Mashape-Authorization", "e1wdzgHAD2mshnZlaKpZkmJF33lNp1AonJFjsnfA0zY6PiYl3E"); // Enter here your Mashape key
	    }
	});

	changeColors();
}

function changeColors() {
	// Pick a random color group
	colorIndex = Math.floor(Math.random() * colors.length);

	// Set the colors
	document.body.style.backgroundColor = colors[colorIndex][0];
	document.getElementById("quotes").style.backgroundColor = colors[colorIndex][1];
	document.getElementById("quote-text").style.color = colors[colorIndex][2];
	document.getElementById("quote-author").style.color = colors[colorIndex][2];
	document.getElementById("new-quote-button").style.background = colors[colorIndex][3];
	document.getElementById("tweet-button").style.background = colors[colorIndex][3];
}

$("button").hover(function(){
    $(this).css("background-color", colors[colorIndex][4]);
    }, function(){
    $(this).css("background-color", colors[colorIndex][3]);
});

function shareTweet() {
	window.open('https://twitter.com/share?text=' + '"' + document.getElementById("quote-text").innerHTML + '"' + ' - ' + document.getElementById("quote-author").innerHTML,'','scrollbars=no,menubar=no,height=300,width=650,resizable=yes,toolbar=no,location=no,status=no');
	// + '&url='+ window.location.href
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console