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.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/93f9f9ade9.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="style.css">
<title>Random Quote Generator</title>
</head>
<body id="quote-box">
<div class="container row mx-auto justify-content-center h-100 align-content-center">
<div id="quote-area">
<div id="text" class="d-flex h-100 w-100 justify-content-center align-items-center text-center p-5"></div>
<div id="author-box" class="py-3 px-4">
<p id="author" class="m-0">John Kennedy</p>
</div>
<div class="quote-tri" id="tri-1"></div>
<div class="quote-tri" id="tri-2"></div>
</div>
</div>
<div class="d-flex align-items-center justify-content-between" id="btn-group">
<button class="btn btn-lg" id="new-quote">New Quote</button>
<a href="twitter.com/intent/tweet" id="tweet-quote"><i class="fab fa-twitter-square fa-2x" ></i></a>
</div>
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
<script src="app.js"></script>
</body>
</html>
@import url('https://fonts.googleapis.com/css?family=Libre+Baskerville|Quicksand&display=swap');
:root {
--main-color : #ADD8E6;
--secondary-color: #ffc0cb;
--btn-color: #cff0cc;
--tweet-color: #fed8b1;
}
i, i:hover {
color: black;
}
html, body {
height: 100%;
width: 100%;
font-size: 16px;
}
body {
font-family: 'Quicksand', 'sans-serif';
}
/* quote styings */
#quote-area {
position: relative;
border-radius: 10px;
background-color: var(--main-color);
margin-bottom: 6rem;
height: 352px;
width: 590px;
}
.quote-tri {
position: absolute;
width: 0;
height: 0;
border: 40px solid;
border-color: var(--main-color) var(--main-color) transparent transparent;
right: 100px;
bottom: -13%;
z-index: 1;
display: inline-block;
}
#tri-2 {
right: 410px;
opacity: 0;
border-color: var(--main-color) transparent transparent var(--main-color)
}
#text {
line-height: 2.5rem !important;
font-style: italic;
font-size: 1.5rem;
}
/* author stylings */
#author-box {
position: absolute;
background-color: var(--secondary-color);
border-radius: 10px;
width: auto !important;
white-space: nowrap;
bottom : -110px;
right : 38px;
z-index : -1;
}
/* btn stylings */
.btn {
background-color: var(--btn-color);
margin-right: 2rem !important;
font-size: 1.3rem;
font-weight: lighter;
text-transform: uppercase;
}
#btn-group {
position: absolute;
top: 550px;
left: 60px;
margin-bottom: 15px;
}
/* twitter quote */
#btn-group.special:before {
content: 'Tweet Quote!';
position: absolute;
right: -70px;
top: -40px;
background-color: var(--tweet-color);
padding: .5rem;
font-size: .75rem;
border-radius: 10px;
}
#btn-group.special:after {
content: '';
width: 0;
height: 0;
border: 5px solid;
border-color: var(--tweet-color) transparent transparent var(--tweet-color);
position: absolute;
right: -18px;
top: -7px;
}
// Make object with all the quotes
const quotes = [
{
quote : "I have no special talent. I am only passionately curious.",
author : "Albert Einstein"
},
{
quote : "Doubt can motivate you, so don’t be afraid of it. Confidence and doubt are at two ends of the scale, and you need both. They balance each other out.",
author : "Barbra Steisand"
},
{
quote : "Be thankful for what you have; you’ll end up having more. If you concentrate on what you don’t have, you will never, ever have enough.",
author : "Oprah Winfrey"
},
{
quote : "To be successful you have to be selfish, or else you never achieve. And once you get to your highest level, then you have to be unselfish. Stay reachable. Stay in touch. Don’t isolate.",
author : "Michael Jordan"
},
{
quote : "Ceaseless work, analysis, reflection, writing much, endless self-correction, that is my secret.",
author : "Johann Sebastian Bach"
},
{
quote : "Vulnerability is the essence of romance. It’s the art of being uncalculated, the willingness to look foolish, the courage to say, ‘This is me, and I’m interested in you enough to show you my flaws with the hope that you may embrace me for all that I am but, more important, all that I am not.",
author : "Ashton Kutcher"
},
{
quote : "Dost thou love life? Then do not squander time, for that is the stuff life is made of.",
author : "Benjamin Franklin"
},
{
quote : "Curious that we spend more time congratulating people who have succeeded than encouraging people who have not.",
author : "Neil DeGrasse Tyson"
},
{
quote : "Wisely, and slow. They stumble that run fast.",
author : "William Shakespeare"
},
{
quote : "If you judge people, you have no time to love them.",
author : "Mother Theresa"
},
{
quote : "Imperfection is beauty, madness is genius and it’s better to be absolutely ridiculous than absolutely boring.",
author : "Marilyn Monroe"
},
{
quote : "The future belongs to those who believe in the beauty of their dreams.",
author : "Eleanor Roosevelt"
},
{
quote : "The future belongs to those who prepare for it today.",
author : "Malcolm X"
},
{
quote : "The successful warrior is the average man, with laser-like focus. ",
author : "Bruce Lee"
},
{
quote : "No matter who you are or what you look like, how you started off, or how and who you love, America is a place where you can write your own destiny.",
author : "Barack Obama"
},
{
quote : "I don’t think of all the misery but of the beauty that still remains. ",
author : "Anne Frank"
},
{
quote : "You have power over your mind – not outside events. Realize this, and you will find strength. ",
author : "Marcus Aurelius"
},
{
quote : "By failing to prepare, you are preparing to fail.",
author : "Benjamin Franklin"
},
{
quote : "Ask not what your country can do for you, but what you can do for your country.",
author : "John F. Kennedy"
},
{
quote : "Good artists copy, great artists steal.",
author : "Pablo Picasso"
},
{
quote : "Ask not what your country can do for you, but what you can do for your country.",
author : "John F. Kennedy"
},
{
quote : "For beautiful eyes, look for the good in others; for beautiful lips, speak only words of kindness; and for poise, walk with the knowledge that you are never alone.",
author : "Audrey Hepburn"
},
{
quote : "Everybody wants to be famous, but nobody wants to do the work. I live by that. You grind hard so you can play hard. At the end of the day, you put all the work in, and eventually it’ll pay off. It could be in a year, it could be in 30 years. Eventually, your hard work will pay off.",
author : "Kevin Hart"
},
{
quote : "Impossible is just a big word thrown around by small men who find it easier to live in the world they’ve been given than to explore the power they have to change it. Impossible is not a fact. It’s an opinion. Impossible is not a declaration. It’s a dare. Impossible is potential. Impossible is temporary. Impossible is nothing. ",
author : "Muhammad Ali"
},
{
quote : "I have learned over the years that when one’s mind is made up, this diminishes fear; knowing what must be done does away with fear.",
author : "Rosa Parks"
}
];
// get quote
function getNewQuote(){
$('#text, #author').animate({
opacity : 0
}, 500, function() {
displayNewQuote();
$(this).animate({
opacity : 1
}, 500)
})
}
// add quote to UI
function displayNewQuote() {
const qIndex = Math.floor(Math.random() * quotes.length);
const newQuote = quotes[qIndex].quote;
const newAuthor = quotes[qIndex].author;
$('#text').text(newQuote);
$('#author').text(newAuthor)
}
// quote box animation
var i = 1, left, right, top, bottom;
function quoteAnimation() {
switch (i) {
case 1:
// speech bubble animation
$("#tri-1").animate({
opacity : 0
}, 500, function(){
$("#tri-2").animate({
opacity : 1
}, 500)
});
//author box animation
$("#author-box").animate({
right: '397px',
bottom: '-110px',
});
i++;
break;
case 2:
// speech bubble animation
$("#tri-2").animate({
opacity : 0
}, 500, function(){
$("#tri-1").animate({
opacity : 1
}, 500)
});
//author box animation
$("#author-box").animate({
right: '38px',
bottom: '-110px',
});
i--;
}
}
// event -- click
$(document).ready(function(){
displayNewQuote();
$('#new-quote').click(function() {
quoteAnimation();
getNewQuote();
});
//event -- mouse over tweet quote
$('#tweet-quote').hover(function(){
$('#btn-group').toggleClass('special');
$(this).animate({
'marginBottom' : '+=10px',
}, 'fast', function(){
$(this).animate({
'marginBottom' : '-=10px'
}, 'fast')
})
}, function(){
$('#btn-group').toggleClass('special');
});
}
)
Also see: Tab Triggers