HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="container">
<h1> The Random Quote Machine </h1>
<div id="quotebox">
<p id="quote">"A wizard is never late, nor is he early, he arrives precisely when he means to."</p>
<p id="quoteinfo"><span id="character">Gandalf</span><span id="movie">The Lord of the Rings: The Fellowship of the Ring</span></p>
</div>
<!-- end quotebox div -->
<div id="buttons">
<div id="newquote">New Quote<i id="quoteicon" class="fas fa-comment-alt"></i></div>
<div id="tweetlink"><i id="twittericon" class="fab fa-twitter"></i></div>
</div> <!-- end button div -->
</div> <!-- end container div -->
* {
/* styles to make borders not take on extra space */
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
html {
width: 100%;
height: 100%;
}
body{
width: 100%;
height: 100%;
background: url(http://res.cloudinary.com/dlyons/image/upload/v1525981944/theaterseats-min.jpg);
background-size: cover;
background-position: center;
}
/* Browser style reset so they all play nice */ html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, time, mark, audio, video {
font-size: 100%;
margin: 0;
padding: 0;
outline: 0 none;
vertical-align: baseline;
}
#container{
display: flex;
flex-direction: column;
width: 100%;
max-width: 1150px;
margin: 0 auto;
padding: 0 4%;
text-align: center;
}
h1{
margin: 3.13vw 0;
color: #ffb60a;
font-family: 'Limelight';
font-size: 3.5em;
font-weight: 500;
}
#quotebox{
height: 400px;
padding: 6.25vw;
background: rgba(0, 0, 0, 0.7);
border: 2px dotted #ffb60a;
border-radius: 10px;
transition: height 2s;
}
#quote, #quoteinfo{
color: #ffffff;
font-family: 'Comfortaa';
}
#quotebox #quote{
text-align: left;
font-size: 180%;
font-weight: 400;
}
#quotebox #quoteinfo{
margin: 2% 0;
text-align: right;
}
#character{
margin: 0 2% 0 0;
font-weight: bold;
font-size: 24px;
}
#movie{
font-size: 18px;
font-style: italic;
}
#buttons{
display: flex;
justify-content: flex-end;
}
#newquote{
width: 100%;
max-width: 200px;
min-height: 50px;
margin-top: 1.25vw;
padding: 15px;
align-self: flex-end;
background: #ffb60a;
color: #000000;
font-family: 'Comfortaa';
font-size: 18px;
font-weight: 700;
cursor: pointer;
border-radius: 5px;
-webkit-text-stroke: .15px;
}
#quoteicon{
margin-left: 5%;
}
#quoteicon, #twittericon{
vertical-align: middle;
}
#tweetlink{
display: block;
width: 100%;
max-width: 75px;
min-height: 50px;
margin: 1.25vw 0 0 1.25vw;
padding: 15px;
align-self: flex-end;
background: #1DA1F3;
color: #ffffff;
font-size: 18px;
cursor: pointer;
border-radius: 5px;
}
/* ========== Mobile Styles ========== */
@media only screen and (max-width: 728px){
#quotebox{
height: 375px;
}
#quotebox #quote {
font-size: 150%;
}
#character{
font-size: 115%;
}
#movie{
display: block;
font-size: 85%;
}
}
@media only screen and (max-width: 450px){
#quotebox {
height: 350px;
}
h1{
font-size: 2em;
}
#quotebox #quote {
font-size: 120%;
}
#quotebox #quoteinfo{
margin: 4.25vw 0;
text-align: left;
}
#character{
font-size: 115%;
}
#movie{
display: block;
font-size: 85%;
}
#buttons {
margin-top: 5vw;
justify-content: center;
}
}
// object of quotes
const quotes = {
1 : {
quote : "A wizard is never late, nor is he early, he arrives precisely when he means to.",
character : "Gandalf",
movie : "The Lord of the Rings: The Fellowship of the Ring"
},
2 : {
quote : "Cage goes in the water, you go in the water. Shark's in the water. Our shark.",
character : "Quint",
movie : "Jaws"
},
3 : {
quote : "By Grabthar's hammer...what a savings.",
character : "Alexander Dane",
movie : "Galaxy Quest"
},
4: {
quote : "Somebody in this camp ain't what he appears to be. Right now that may be one or two of us. By Spring, it could be all of us.",
character : "MacReady",
movie : "John Carpenter's The Thing"
},
5: {
quote : "Wendy? Darling? Light, of my life. I'm not gonna hurt ya. You didn't let me finish my sentence. I said, I'm not gonna hurt ya. I'm just going to bash your brains in!",
character : "Jack Torrance",
movie : "The Shining"
},
6 : {
quote : "I think that I am familiar with the fact that you are going to ignore this particular problem until it swims up and BITES YOU ON THE ASS!",
character : "Hooper",
movie : "Jaws"
},
7 : {
quote : "HEY! Don't open that! It's an alien planet! Is there air? You don't know! ",
character : "Guy Fleegman",
movie : "Galaxy Quest"
},
8: {
quote : "It's good to meet you, Dr. Banner. Your work on anti-electron collisions is unparalleled. And I'm a huge fan of the way you lose control and turn into an enormous green rage monster.",
character : "Tony Stark",
movie : "Avengers"
},
9 : {
quote : "You met me at a very strange time in my life",
character : "Narrator",
movie : "Fight Club"
},
10: {
quote : "Where is the horse and the rider? Where is the horn that was blowing? They have passed like rain on the mountain, like wind in the meadow. The days have gone down in the West behind the hills into shadow. How did it come to this?",
character : "Theoden",
movie : "The Lord of the Rings: The Two Towers"
},
11 : {
quote : "If my calculations are correct, when this baby hits 88 miles per hour... you're gonna see some serious shit.",
character : "Dr. Emmett Brown",
movie : "Back to the Future"
},
12 : {
quote : "Ray, when someone asks you if you're a god, you say, \"YES!\"",
character : "Winston Zeddemore",
movie : "Ghostbusters"
},
13 : {
quote : "Why worry? Each one of us is carrying an unlicensed nuclear accelerator on his back.",
character : "Dr. Peter Venkman",
movie : "Ghostbusters"
},
14 : {
quote : "Good evening, Clarice",
character : "Hannibal Lecter",
movie : "Silence of the Lambs"
},
15 : {
quote : "After that my guess is that you'll never hear from him again. The greatest trick the devil ever pulled was convincing the world he didn't exist. And like that...he's gone.",
character : "Verbal",
movie : "The Usual Suspects"
},
16 : {
quote : "Size matters not. Look at me. Judge me by my size, do you? Hmm? Hmm. And well you should not. For my ally is the Force, and a powerful ally it is.",
character : "Yoda",
movie : "Star Wars: The Empire Strikes Back"
},
17 : {
quote : "That's it, man. Game over, man. Game over!",
character : "Private Hudson",
movie : "Aliens"
},
18 : {
quote : "We'd better get back 'cause it'll be dark soon and they mostly come at night. Mostly.",
character : "Newt",
movie : "Aliens"
},
19 : {
quote : "Mawwiage. Mawwiage is wat bwings us togeder today. Mawwiage, that bwessed awwangement, that dweam wifin a dream… And wuv, twue wuv, will fowwow you foweva… So tweasure your wuv— ",
character : "The Impressive Clergyman",
movie : "The Princess Bride"
},
20 : {
quote : "Every man dies, not every man really lives.",
character : "William Wallace",
movie : "Braveheart"
},
21 : {
quote : "Are you saying that I put an abnormal brain into a seven and a half foot long, fifty-four inch wide GORILLA?",
charater : "Dr. Frederick Fronkensteen",
movie : "Young Frankenstein"
},
22 : {
quote : "Vee had better confeerm de fect dat Yunk Frankenshtein iss indeed VALLOWING EEN EES GANDFADDA'S VOOTSHTAPS",
character : "Inspector Kemp",
movie : "Young Frankenstein"
},
23 : {
quote : "The unknown future rolls toward us. I face it, for the first time, with a sense of hope. Because if a machine, a Terminator, can learn the value of human life, maybe we can too.",
character : "Sarah Connor",
movie : "Terminator 2"
},
24 : {
quote : "Nicholas Angel: Are there any questions?\n\nDanny Butterman: Is it true that there's a point on a man's head where if you shoot it, it will blow up?",
movie : "Hot Fuzz"
},
25 : {
quote : "Dr. Richard Kimble: I didn't kill my wife!\n\nDeputy Marshal Samuel Gerard: I don't care!",
movie : "The Fugitive"
},
26 : {
quote : "As Mr. Sloan always says, there is no \"I\" in team, but there is an \"I\" in pie. And there's an \"I\" in meat pie. Anagram of meat is team... I don't know what he's talking about.",
character : "Shaun",
movie : "Shaun of the Dead"
},
27 : {
quote : "Dr. Rumack: Can you fly this plane, and land it?\n\nTed Striker: Surely you can't be serious.\n\nDr. Rumack: I am serious... and don't call me Shirley.",
movie : "Airplane!"
},
28 : {
quote : "I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time... like tears in rain... Time to die.",
character : "Batty",
movie : "Blade Runner"
},
29 : {
quote : "John Hammond: All major theme parks have delays. When they opened Disneyland in 1956, nothing worked!\n\nDr. Ian Malcolm: Yeah, but, John, if The Pirates of the Caribbean breaks down, the pirates don't eat the tourists.",
movie : "Jurassic Park"
},
30 : {
quote : "Your scientists were so preoccupied with whether they could, they didn’t stop to think if they should.",
character : "Dr. Ian Malcolm",
movie : "Jurassic Park"
},
31 : {
quote : "Hail to the king, baby.",
character : "Ash Williams",
movie : "Army of Darkness"
}
};
// HTML elements in the DOM
let quoteDisplay = document.getElementById("quote");
let characterDisplay = document.getElementById("character");
let movieDisplay = document.getElementById("movie");
let quoteButton = document.getElementById("newquote");
let tweetButton = document.getElementById("tweetquote");
let tweetLink = document.getElementById("tweetlink");
// first get the max number of quotes
let quoteLength = 0;
for (let quote in quotes){
quoteLength ++;
}
// create holder variables
let oldNum;
let currentNum;
let nextNum;
let formattedQuote;
function getQuote(){
let min = Math.ceil(1);
let max = Math.floor(quoteLength);
nextNum = Math.floor(Math.random() * (max - min + 1)) + min;
oldNum = currentNum;
currentNum = nextNum;
// update the HTML elements, check for \n in quotes with multiple characters talking
urlFormattedQuote = quotes[nextNum].quote.replace(new RegExp('\n','g'), '%0A');
let machineURL = '<a href="#">The Random Quote Machine!</a>'
quoteDisplay.innerHTML = quotes[nextNum].quote.replace(new RegExp('\r?\n','g'), '<br />');
characterDisplay.textContent = quotes[nextNum].character;
movieDisplay.textContent = quotes[nextNum].movie;
// check if the previous number matches the new one, if it does, run the generator again
if (nextNum === oldNum){
getQuote();
}
}
// run generator function on initial page load
getQuote();
// run generator function on button click
quoteButton.addEventListener("click", function(){
getQuote();
});
// tweet quote on button click
tweetLink.addEventListener("click", function(){
// check to see if character is undefined (conversation quotes)
if(quotes[nextNum].character == undefined){
quotes[nextNum].character = " ";
}
// open the twitter form in a popup window
window.open("https://twitter.com/intent/tweet?text=" + urlFormattedQuote + " -" + quotes[nextNum].character + " (" + quotes[nextNum].movie + ")","", "width=450,height=500,resizable");
});
Also see: Tab Triggers