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 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.
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.
If the stylesheet 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 CSS 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.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.
Upgrade to PROIf 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.
Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.
Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:
Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.
This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.
Upgrade to PRO
<div class="container">
<div id="quoteCard" class="row quote-card">
<div class="col s12 m6 offset-m3">
<div class="card hoverable">
<div class="card-content">
<blockquote><p id="phrase">"Sometimes it is the people no one can imagine anything of, who do the things no one can imagine."</p><footer><cite id="author">- Alan Turing</cite></footer></blockquote>
<a onClick="tweetIt()" href="https://twitter.com/intent/tweet" target="_blank"><i class="fa fa-twitter fa-lg" aria-hidden="true"></i></a>
<a class="right" href="#" id="newQuote">New Quote</a>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<a class="waves-effect waves-light btn blue lighten-2 hoverable" id="linkToPortfolio" href="https://njm8.github.io/" target="_blank">Created by Nate Mallison</a>
</div>
html {
background: url('https://github.com/NJM8/FreeCodeCampFrontEndProjects/blob/master/randomQuoteGenerator/01860_sanfrancisco_2560x1600.jpg?raw=true') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.quote-card {
position: absolute;
top: 0px;
left: 0px;
padding-top: 125px;
padding-left: 200px;
z-index: 10;
}
.card {
width: 400px;
}
.linkToPortfolio {
position: absolute;
}
@media screen and (max-width: 1024px) {
img {
left: 50%;
margin-left: -512px;
}
}
function tweetIt () {
var phrase = document.getElementById('phrase').innerText;
var author = document.getElementById('author').innerText;
var tweetUrl = 'https://twitter.com/intent/tweet?text=' +
encodeURIComponent(phrase) + " " + encodeURIComponent(author);
window.open(tweetUrl);
}
var quotes = {
quote_0: {
id: 0,
phrase: "People often say that motivation doesn’t last. Well, neither does bathing. That’s why we recommend it daily.",
author: "Zig Ziglar"
},
quote_1: {
id: 1,
phrase: "The best time to plant a tree was 20 years ago, the second best time is now.",
author: "Chinese Proverb"
},
quote_2: {
id: 2,
phrase: "It does not matter how slowly you go as long as you do not stop.",
author: "Confucius"
},
quote_3: {
id: 3,
phrase: "In the end, it's not the years in your life that count. It's the life in your years.",
author: "Abraham Lincoln"
},
quote_4: {
id: 4,
phrase: "However bad life may seem, there is always something you can do, and succeed at. While there is life, there is hope.",
author: "Stephen Hawking"
},
quote_5: {
id: 5,
phrase: "Always do right. This will gratify some people and astonish the rest. ",
author: "Mark Twain"
},
quote_6: {
id: 6,
phrase: "Every strike brings me closer to the next home run.",
author: "Babe Ruth"
},
quote_7: {
id: 7,
phrase: "The mind is everything. What you think you become.",
author: "Buddha"
},
quote_8: {
id: 8,
phrase: "Your time is limited, so don’t waste it living someone else’s life.",
author: "Steve Jobs"
},
quote_9: {
id: 9,
phrase: "You can never cross the ocean until you have the courage to lose sight of the shore.",
author: "Christopher Columbus"
},
quote_10: {
id: 10,
phrase: "If you hear a voice within you say “you cannot paint,” then by all means paint and that voice will be silenced.",
author: "Vincent Van Gogh"
},
quote_11: {
id: 11,
phrase: "The best way to predict the future is to create it." ,
author: "Abraham Lincoln"
},
quote_12: {
id: 12,
phrase: "When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'Happy'. They told me I didn't understand the assignment and I told them they didn't understand life." ,
author: "John Lennon"
},
quote_13: {
id: 13,
phrase: "If today were the last day of your life, would you want to do what you are about to do today?" ,
author: "Steve Jobs"
},
quote_14: {
id: 14,
phrase: "Have no fear of perfection, you'll never reach it." ,
author: "Salvador Dali"
},
quote_15: {
id: 15,
phrase: "The greatest glory in living lies not in never falling, but in rising every time we fall." ,
author: "Nelson Mandela"
},
quote_16: {
id: 16,
phrase: "We cannot solve our problems with the same thinking used when we created them." ,
author: "Albert Einstein"
},
quote_17: {
id: 17,
phrase: "Do not pray for an easy life, pray for the strength to endure a difficult one." ,
author: "Bruce Lee"
},
quote_18: {
id: 18,
phrase: "If you cannot fly, then run. If you cannot run, then walk. If you cannot walk then crawl, but whatever you do, you have to keep moving forward." ,
author: "Martin Luther King Jr."
},
quote_19: {
id: 19,
phrase: "If you truly love life, don't waste time; because time is what life is made of." ,
author: "Bruce Lee"
},
quote_20: {
id: 20,
phrase: "However bad life may seem, there is always something you can do, and succeed at. While there is life, there is hope." ,
author: "Stephen Hawking"
}
}
$("#newQuote").click(function(){
$("#quoteCard").fadeOut("slow", function(){
showNewQuote();
})
});
function showNewQuote(){
var randNum = Math.floor(Math.random() * 20 + 1);
var newQuote = "";
var newAuthor = "";
var newTopPadding = Math.floor(Math.random() * 600 + 1);
var newLeftPadding = Math.floor(Math.random() * 600 + 1);
for (var key in quotes) {
for (var key2 in quotes[key]){
if (quotes[key][key2] === randNum) {
newQuote = quotes[key].phrase;
newAuthor = quotes[key].author;
}
}
}
$("#phrase").html(newQuote);
$("#author").html(newAuthor);
$("#quoteCard").css({"padding-top": newTopPadding});
$("#quoteCard").css({"padding-left": newLeftPadding});
$("#quoteCard").fadeIn("slow", function(){
});
};
Also see: Tab Triggers