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 class="wrap">
<!-- <button class="toast-btn">Make a toast</button> -->
<div class="toast">
<div class="container open">
<div class="msg">
<span class="error-msg main-msg">Please resolve
<span class="error-num"></span>
errors in order to submit your document
</span>
<span class="error-msg">Something bad happened here</span>
<span class="error-msg">An error occurred there</span>
<span class="error-msg">Something bad happened everywhere</span>
<span class="error-msg">A bad thing happened, it should be fixed</span>
<span class="error-msg">Something bad definitely happened</span>
</div>
</div>
<i class="fas fa-chevron-down icon open"></i>
</div>
<div class="orderset">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam euismod sit amet justo ut dignissim. In rhoncus nunc et nulla mollis egestas. Vestibulum sit amet libero sollicitudin, lacinia lacus vel, pulvinar eros. Ut mollis eros id nibh finibus consectetur. Donec condimentum ligula eget efficitur fermentum. Donec at varius purus, sagittis ullamcorper dolor. Fusce aliquet mi et nulla faucibus tincidunt. Vestibulum scelerisque turpis a venenatis aliquam. Maecenas fermentum leo nisi, eget pretium sem maximus a. Praesent tristique mi porttitor, molestie sem vitae, pellentesque dui. Duis imperdiet sapien mattis ex interdum, quis pellentesque magna malesuada. Maecenas dignissim arcu orci, nec vehicula tellus hendrerit non. Quisque pretium metus non massa imperdiet, ut egestas ante hendrerit. Aenean mollis blandit arcu, id faucibus lorem porttitor fringilla. Nulla pellentesque tempor mi tempor maximus. Duis non porttitor purus.</p>
<p>Proin sem dolor, malesuada sit amet felis at, pellentesque volutpat felis. Pellentesque fringilla erat a mauris blandit maximus. Cras vel tellus nec felis vulputate elementum non non arcu. Suspendisse condimentum metus a arcu condimentum venenatis. Mauris hendrerit massa et dui consectetur ultricies. Praesent velit metus, luctus imperdiet ornare et, consectetur id massa. Quisque malesuada tortor ex, quis tincidunt dolor lacinia nec. Fusce dapibus lacinia arcu, vel tincidunt dolor congue at. Nullam a condimentum turpis, tincidunt congue purus. Nunc faucibus, nunc vitae porttitor efficitur, nisl nibh euismod quam, mattis hendrerit ex mauris ac turpis. Vivamus consequat enim sed faucibus iaculis.</p>
<p>Aliquam et mi eget turpis pellentesque finibus. Curabitur ut sapien blandit, dignissim ipsum a, mattis nibh. Nulla in lectus eu metus cursus mattis. In ut dolor id neque blandit commodo. Aenean in eleifend elit, ut fringilla velit. Morbi a molestie orci. Etiam et ullamcorper purus. Donec id imperdiet risus, ut porttitor lacus. Vestibulum eu molestie turpis. Aenean tincidunt dapibus maximus. Nulla nec malesuada leo.</p>
<p>Pellentesque libero leo, bibendum vel efficitur vel, consectetur at mi. Pellentesque ornare turpis vitae neque suscipit, id molestie sapien interdum. Nulla volutpat malesuada vulputate. Fusce pulvinar egestas tellus quis sodales. Sed nec ullamcorper metus. Suspendisse at dapibus tellus. Suspendisse potenti.</p>
<p>Vestibulum purus enim, imperdiet a lorem non, lacinia ornare sapien. Nam id nisi magna. Aliquam cursus diam vel tempus scelerisque. Etiam vitae nibh velit. Vestibulum mauris purus, dapibus sed tincidunt id, ultrices ac ex. Nunc eget nulla consequat, viverra nisl quis, mattis velit. Sed sit amet rhoncus quam. Nullam vitae velit semper, interdum justo in, luctus urna. In pellentesque vel orci pellentesque viverra.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam euismod sit amet justo ut dignissim. In rhoncus nunc et nulla mollis egestas. Vestibulum sit amet libero sollicitudin, lacinia lacus vel, pulvinar eros. Ut mollis eros id nibh finibus consectetur. Donec condimentum ligula eget efficitur fermentum. Donec at varius purus, sagittis ullamcorper dolor. Fusce aliquet mi et nulla faucibus tincidunt. Vestibulum scelerisque turpis a venenatis aliquam. Maecenas fermentum leo nisi, eget pretium sem maximus a. Praesent tristique mi porttitor, molestie sem vitae, pellentesque dui. Duis imperdiet sapien mattis ex interdum, quis pellentesque magna malesuada. Maecenas dignissim arcu orci, nec vehicula tellus hendrerit non. Quisque pretium metus non massa imperdiet, ut egestas ante hendrerit. Aenean mollis blandit arcu, id faucibus lorem porttitor fringilla. Nulla pellentesque tempor mi tempor maximus. Duis non porttitor purus.</p>
<p>Proin sem dolor, malesuada sit amet felis at, pellentesque volutpat felis. Pellentesque fringilla erat a mauris blandit maximus. Cras vel tellus nec felis vulputate elementum non non arcu. Suspendisse condimentum metus a arcu condimentum venenatis. Mauris hendrerit massa et dui consectetur ultricies. Praesent velit metus, luctus imperdiet ornare et, consectetur id massa. Quisque malesuada tortor ex, quis tincidunt dolor lacinia nec. Fusce dapibus lacinia arcu, vel tincidunt dolor congue at. Nullam a condimentum turpis, tincidunt congue purus. Nunc faucibus, nunc vitae porttitor efficitur, nisl nibh euismod quam, mattis hendrerit ex mauris ac turpis. Vivamus consequat enim sed faucibus iaculis.</p>
<p>Aliquam et mi eget turpis pellentesque finibus. Curabitur ut sapien blandit, dignissim ipsum a, mattis nibh. Nulla in lectus eu metus cursus mattis. In ut dolor id neque blandit commodo. Aenean in eleifend elit, ut fringilla velit. Morbi a molestie orci. Etiam et ullamcorper purus. Donec id imperdiet risus, ut porttitor lacus. Vestibulum eu molestie turpis. Aenean tincidunt dapibus maximus. Nulla nec malesuada leo.</p>
<p>Pellentesque libero leo, bibendum vel efficitur vel, consectetur at mi. Pellentesque ornare turpis vitae neque suscipit, id molestie sapien interdum. Nulla volutpat malesuada vulputate. Fusce pulvinar egestas tellus quis sodales. Sed nec ullamcorper metus. Suspendisse at dapibus tellus. Suspendisse potenti.</p>
<p>Vestibulum purus enim, imperdiet a lorem non, lacinia ornare sapien. Nam id nisi magna. Aliquam cursus diam vel tempus scelerisque. Etiam vitae nibh velit. Vestibulum mauris purus, dapibus sed tincidunt id, ultrices ac ex. Nunc eget nulla consequat, viverra nisl quis, mattis velit. Sed sit amet rhoncus quam. Nullam vitae velit semper, interdum justo in, luctus urna. In pellentesque vel orci pellentesque viverra.</p>
</div>
</div>
<!-- <div class="orderset">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam euismod sit amet justo ut dignissim. In rhoncus nunc et nulla mollis egestas. Vestibulum sit amet libero sollicitudin, lacinia lacus vel, pulvinar eros. Ut mollis eros id nibh finibus consectetur. Donec condimentum ligula eget efficitur fermentum. Donec at varius purus, sagittis ullamcorper dolor. Fusce aliquet mi et nulla faucibus tincidunt. Vestibulum scelerisque turpis a venenatis aliquam. Maecenas fermentum leo nisi, eget pretium sem maximus a. Praesent tristique mi porttitor, molestie sem vitae, pellentesque dui. Duis imperdiet sapien mattis ex interdum, quis pellentesque magna malesuada. Maecenas dignissim arcu orci, nec vehicula tellus hendrerit non. Quisque pretium metus non massa imperdiet, ut egestas ante hendrerit. Aenean mollis blandit arcu, id faucibus lorem porttitor fringilla. Nulla pellentesque tempor mi tempor maximus. Duis non porttitor purus.</p>
<p>Proin sem dolor, malesuada sit amet felis at, pellentesque volutpat felis. Pellentesque fringilla erat a mauris blandit maximus. Cras vel tellus nec felis vulputate elementum non non arcu. Suspendisse condimentum metus a arcu condimentum venenatis. Mauris hendrerit massa et dui consectetur ultricies. Praesent velit metus, luctus imperdiet ornare et, consectetur id massa. Quisque malesuada tortor ex, quis tincidunt dolor lacinia nec. Fusce dapibus lacinia arcu, vel tincidunt dolor congue at. Nullam a condimentum turpis, tincidunt congue purus. Nunc faucibus, nunc vitae porttitor efficitur, nisl nibh euismod quam, mattis hendrerit ex mauris ac turpis. Vivamus consequat enim sed faucibus iaculis.</p>
<p>Aliquam et mi eget turpis pellentesque finibus. Curabitur ut sapien blandit, dignissim ipsum a, mattis nibh. Nulla in lectus eu metus cursus mattis. In ut dolor id neque blandit commodo. Aenean in eleifend elit, ut fringilla velit. Morbi a molestie orci. Etiam et ullamcorper purus. Donec id imperdiet risus, ut porttitor lacus. Vestibulum eu molestie turpis. Aenean tincidunt dapibus maximus. Nulla nec malesuada leo.</p>
<p>Pellentesque libero leo, bibendum vel efficitur vel, consectetur at mi. Pellentesque ornare turpis vitae neque suscipit, id molestie sapien interdum. Nulla volutpat malesuada vulputate. Fusce pulvinar egestas tellus quis sodales. Sed nec ullamcorper metus. Suspendisse at dapibus tellus. Suspendisse potenti.</p>
<p>Vestibulum purus enim, imperdiet a lorem non, lacinia ornare sapien. Nam id nisi magna. Aliquam cursus diam vel tempus scelerisque. Etiam vitae nibh velit. Vestibulum mauris purus, dapibus sed tincidunt id, ultrices ac ex. Nunc eget nulla consequat, viverra nisl quis, mattis velit. Sed sit amet rhoncus quam. Nullam vitae velit semper, interdum justo in, luctus urna. In pellentesque vel orci pellentesque viverra.</p>
</div> -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
html, body {
height: 100%;
}
body {
display: flex;
flex-wrap: wrap;
align-items: top;
justify-content: center;
background: #fff;
font-family: "PT Sans";
color: #212121;
padding-top: 20px;
font-family: 'Helvetica';
}
.orderset {
width: 920px;
padding: 16px;
border: 3px solid #727272;
margin: 16px auto;
p {
margin-bottom: 24px;
}
}
.toast {
width: 80vw;
min-height: 2em;
border-radius: 3px;
padding: 8px;
background-color: #ffeaea;
border: 1px solid rgb(255,0,0);
display: flex;
align-items: top;
position: sticky;
top: 20px;
z-index: 2;
margin: 0 auto;
.container {
display: flex;
flex: 1;
max-height: 1000px;
overflow: hidden;
transition: max-height 650ms ease-in-out;
padding: 8px;
&.close {
max-height: 16px;
&.msg {
display: none;
}
}
.msg {
flex: 1;
flex-wrap: wrap;
color: #ff0000;
font-size: 1em;
display: flex;
.error-msg {
display: flex;
flex-grow:1;
flex-basis: 100%;
justify-content: center;
opacity: 1;
transition: opacity 300ms, height 300ms;
height: 22px;
&.main-msg {
// opacity: 0;
height: 40px;
color: #555555;
font-weight: bold;
}
}
}
}
.fas {
color: #555555;
display: flex;
width: 60px;
flex: 0;
padding: 8px;
transition: all 300ms;
height: 14px;
transform-origin: 50% 50%;
&.close {
transform: rotate(180deg);
}
}
}
const closeBtn = document.querySelector('.icon');
const container = document.querySelector('.container');
let errs = document.querySelector('.msg').childElementCount;
let errNum = document.querySelector('.error-num');
let errTotal = errs - 1;
console.log(errNum);
console.log(errTotal);
const displayErrorTotal = `
<span class="number">\u00A0${errTotal}\u00A0</span>
`;
errNum.innerHTML = displayErrorTotal;
closeBtn.addEventListener('click', function(){
// alert('clicked');
let first = 'close';
let second = 'open';
if(container.classList.contains(first)) {
[first, second] = [second, first]
}
//if open, switch order of toggle!
container.classList.toggle(first);
container.classList.toggle(second);
closeBtn.classList.toggle(first);
closeBtn.classList.toggle(second);
});
// /*
// NOTE: Babel is enabled, which translates much of the below to ES5 compatible code.
// https://github.com/google/traceur-compiler
// An alternative is 6to5: https://6to5.org/
// Helpful docs for getting up to speed on ES6: https://6to5.org/docs/learn-es6/
// */
// // Convenience function for logging. Look funny? It won't by the end of this.
// let _ = msg => console.log(msg);
// /*
// * let is the new var
// */
// let someVariable = 'some value';
// _(someVariable); // some value
// // Value is mutable
// someVariable = 'another value';
// _(someVariable); // another value
// // This would cause an error, cannot redeclare in the same block/scope.
// // let someVariable = 'yet another value';
// // This is OK, as it's a different block/scope.
// function something() {
// let someVariable = 'yet another value';
// // do stuff
// }
// /*
// * Constants
// * Cannot be changed once they are set.
// */
// const a = 'Some string';
// // The following line would generate an error. 'a' is read only.
// // a = 'Another string';
// /*
// * Template strings
// */
// let firstName = 'Brad';
// let lastName = 'Daily';
// _(`My name is ${firstName} ${lastName}.`); // My name is Brad Daily.
// // Can be multiline too
// let multilineString = `My name is ${firstName} ${lastName}.
// Really nice to meet ya.`;
// _(multilineString); // My name is Brad Daily.\nReally nice to meet ya.
// /*
// * 'Spread' operator
// * Creates an array from all passed arguments
// */
// let spread = function(...x) {
// return x;
// }
// _(spread(1, 2, 3)); // [1, 2, 3]
// /*
// * Fat arrow function syntax
// */
// /* Old way
// var helloWorld = function() {
// return 'Hello world';
// }
// */
// let helloWorld = () => 'Hello world.';
// _(helloWorld()); // Hello world.
// // Here's that spread function from earlier
// let newSpread = (...x) => x;
// _(newSpread(3, 4, 5)); // [3, 4, 5]
// // Example using spread operator plus arrow functions.
// // add() will sum any numbers passed to it as arguments.
// let add = (...x) => x.reduce((previous, current) => previous + current);
// _(add(1, 5, 10, 20)); // 36
// // Array sort
// _([1, 5, 8, 2, 3, 4].sort((a, b) => a < b ? -1 : 1)); // [1, 2, 3, 4, 5, 8]
// // Arrow functions inherit the scope they are defined in.
// // No more var self = this;
// // See: this.owner in the sayFruits function
// let pantry = {
// owner: 'Jim',
// fruits: ['apple', 'orange', 'pear'],
// sayFruits() {
// this.fruits.forEach(fruit => {
// _(`${this.owner}'s pantry has ${fruit}s`);
// });
// }
// }
// pantry.sayFruits();
// // Jim's pantry has apples
// // Jim's pantry has oranges
// // Jim's pantry has pears
// /*
// * Object literals
// */
// let x = 50;
// let y = 100;
// /* Old way
// var coordinates = {
// x: x,
// y: y
// }
// */
// let coordinates = {
// x, y
// };
// _(coordinates); // Object { x: 50, y: 100}
// /*
// * Destructuring
// */
// let http = () => [404, 'Not found'];
// let [status, textResponse] = http();
// _(status); // 404
// _(textResponse); // Not found
// /*
// * Classes
// */
// class Person {
// constructor(firstName, lastName, age) {
// this.firstName = firstName;
// this.lastName = lastName;
// this.age = age;
// }
// // Getters allow for dynamic properties
// // In this example, you can use .fullName instead of .fullName()
// // See the greeting() function below
// get fullName() {
// return `${this.firstName} ${this.lastName}`;
// }
// greeting() {
// return `Hi, my name is ${this.fullName} and I am ${this.age} years old.`;
// }
// isAdult() {
// return this.age >= 18;
// }
// }
// let me = new Person('Brad', 'Daily', 35);
// _(me.isAdult()); // true
// _(me.greeting()); // Hi, my name is Brad Daily and I am 35 years old.
// me.age = 36;
// _(me.greeting()); // Hi, my name is Brad Daily and I am 36 years old.
// // Class extension
// class Pirate extends Person {
// greeting() {
// return `Arggh, me name is ${this.fullName} and I've been sailing these here seas for ${this.age} years.`;
// }
// }
// var pirate = new Pirate('Brad', 'Daily', 35);
// _(pirate.greeting()); // Arggh, me name is Brad Daily and I've been sailing these here seas for 35 years.
// /*
// * Default parameters values
// */
// function repeat(toldYa = 'Nothin') {
// return `You told me ${toldYa}.`;
// }
// _(repeat()); // You told me Nothin'.
// _(repeat("Somethin'")); // You told me Somethin'.
// // Arrow version
// let repeat2 = (toldYa = "Nothin'") => `You told me ${toldYa}.`;
// _(repeat2()); // You told me Nothin'.
// _(repeat2("Somethin'")); // You told me Somethin'.
// /*
// * Sets
// */
// let letters = new Set();
// letters.add('A');
// _(letters.size); // 1
// // Ignores duplicate values
// letters.add('A');
// _(letters.size); // 1
// _(letters.has('A')); // true
// _(letters.has('B')); // false
// letters.add('B');
// for (let letter of letters) _(letter); // Outputs A, then B
// _(letters.delete('Z')); // returns false since Z is was not in letters before delete()
// _(letters.delete('A')); // returns true since A is was in letters before delete()
// letters.clear();
// _(letters.size); // 0
// /*
// * Maps
// */
// let map = new Map();
// map.set('string-key', 'I belong to the string-key');
// // Keys can be anything, like a DOM element
// map.set(document.getElementsByTagName('h1')[0], 'I belong to the first <h1> in the DOM.');
// _(map.size); // 2
// _(map.get(document.getElementsByTagName('h1')[0])); // I belong to the first <h1> in the DOM.
// for (let [key, val] of map.entries()) {
// _(key); // Outputs 'string-key', then the <h1>
// _(val); // Outputs 'I belong to the string-key', then 'I belong to the first <h1> in the DOM.'
// }
Also see: Tab Triggers