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="demo-brand">DEMO</div>
<main>
<section class="purpose">
<article>
<h2>What's the matter?</h2>
<p>
It is a matter of consenting to the
pollution caused by solid waste and the inefficient
and the inefficient use of plastic in disposal.
The plastic we use can be put to more efficient uses, and one of them is
creating eco-friendly plastic bricks to build houses for the homeless.
houses for the homeless.
Social media can change society,
because let's face it, young people right now, many of them are very young.
are influenced by social networks or directly by what they find relevant and they pay more attention
to it.
They are influenced by social networks or directly by what seems relevant to them and they pay more
attention to it than to something that appears in a newspaper.
With this we can know that a simple post on the internet can change things, so why not use it in the
right way?
That's why I have created this application, to simulate a situation
situation where you start recycling and you have the possibility to upload a post related to the
related to the consent of contamination, which can make more people recycling the same
that there are more people recycling the same as you, and you can recycle more per day,
because there are more people recycling the same as you and donating.
</p>
</article>
</section>
<header>
<h1 class="header-title">Statistics</h1>
<section class="co2-emission">
<article class="co2-emission-info">
<h2>CO2 EMISSION</h2>
<span id="emission-counter">
780 grams
</span>
</article>
</section>
<section class="pollution-consent">
<article class="pollution-consent-info">
<h2>Consented persons</h2>
<span id="consented-counter">
500
</span>
</article>
</section>
<section class="houses-built">
<article class="houses-built-info">
<h2>houses built</h2>
<span id="built-counter">
850
</span>
</article>
</section>
</header>
<section class="bottles-recycled">
<article class="recycled-info">
<h2>
Recycled bottles - 2,5 m grams per house
</h2>
<h3>Bottles recycled x People consented</h3>
<span id="recycled-counter">
100 x 500
</span>
</article>
</section>
<section class="actions">
<article class="buttons">
<button class="recycle" id="recycle_btn">Recycle</button>
<button class="post" id="post_btn">Make a post!</button>
</article>
</section>
</main>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
main {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
header {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
margin-bottom: 30px;
}
.header-title {
flex: 1 1 100%;
text-align: center;
margin-bottom: 10px;
}
.co2-emission,
.pollution-consent,
.houses-built {
flex-basis: 100%;
margin-bottom: 10px;
}
.co2-emission-info,
.pollution-consent-info,
.houses-built-info {
padding: 20px;
background-color: #f5f5f5;
border-radius: 5px;
text-align: center;
}
.bottles-recycled,
.actions {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-bottom: 20px;
}
.recycled-info {
flex-basis: 100%;
}
.buttons {
flex-basis: 100%;
}
button {
display: block;
width: 100%;
padding: 10px;
font-size: 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.demo-brand {
position: fixed;
top: 10px;
left: 10px;
padding: 10px;
background-color: #000;
color: #fff;
font-weight: bold;
}
@media screen and (min-width: 600px) {
header {
justify-content: space-between;
}
.header-title {
flex: 0 0 100%;
margin-bottom: 0;
}
.co2-emission,
.pollution-consent,
.houses-built {
flex-basis: calc(33.33% - 10px);
margin-bottom: 10px;
}
.recycled-info {
flex-basis: calc(50% - 10px);
}
}
/*
Author: Char
This code was made for reusability and readability purposes.
*/
// Functions
// Renders the data on the webpage
function render() {
const {
emission,
consented,
houses,
recycled,
plasticGRecycled,
homelessSaved
} = actualData;
saved();
emissionCounter.innerText = `${emission / 1000000} tons`; // Displays the emission value in tons
consentedCounter.innerText = consented; // Displays the consented value
housesCounter.innerText = `${houses} (${homelessSaved} people in total)`; // Displays the number of houses and the total number of people saved
recycledBottlesCounter.innerText = `${recycled} (${plasticGRecycled}g) x ${consented}`; // Displays the number of recycled bottles, the total weight of recycled plastic, and the consented value
return actualData;
}
// Checks if a certain number of people have been saved and displays an alert message if true
function saved() {
let demo_limit = 10;
if (actualData.homelessSaved >= demo_limit) {
alert(`You gave a home to ${demo_limit} people`);
alert("I think you should use this solution in more places, and with a different social method.");
alert("Thanks for the help! - Char and everyone.");
setDefault();
}
}
// Calculates the number of houses that can be built based on the amount of recycled plastic
function calcHouses() {
let bricks = Math.floor(actualData.recycledTotal / plasticPerBrick);
let houses = Math.floor(bricks / bricksPerHouse);
return houses;
}
// Updates the data when the recycle button is clicked
function recycle() {
actualData.recycled += 1;
actualData.recycledTotal = actualData.recycled * actualData.consented;
actualData.plasticGRecycled = actualData.recycledTotal * gPerBottle;
actualData.emission -= emissionPerBottle * actualData.recycledTotal;
actualData.emission += emissionPerBottle * actualData.recycledTotal + 50;
actualData.houses = calcHouses();
actualData.homelessSaved = Math.floor(actualData.houses * peoplePerHouse);
}
// Simulates a social media post and updates the data accordingly
function doPost() {
let follows = Math.floor(Math.random() * followersRandomLimit);
follows = (follows == 0) ? 1 : follows;
console.log(`+Follows ${follows}`);
actualData.consented += follows;
}
// Retrieves data from the local storage
function getData() {
return JSON.parse(localStorage.getItem('bottles'));
}
// Updates the data in the local storage
function updateData() {
const stringifyedObject = JSON.stringify(actualData);
localStorage.setItem('bottles', stringifyedObject);
}
// Sets the default values for the data
function setDefault() {
actualData = defaultSchema;
const stringifyedObject = JSON.stringify(defaultSchema);
localStorage.setItem('bottles', stringifyedObject);
}
// Checks if the user has any stored data and updates the webpage accordingly
function checkData() {
let data = getData();
if (!data) {
console.log("The user has no data stored");
setDefault();
render();
return false;
} else {
console.log("The user has data stored");
actualData = getData();
render();
return true;
}
}
// Main document objects
const emissionCounter = document.getElementById("emission-counter");
const consentedCounter = document.getElementById("consented-counter");
const housesCounter = document.getElementById("built-counter");
const recycledBottlesCounter = document.getElementById("recycled-counter");
const recycleBtn = document.getElementById("recycle_btn");
const postBtn = document.getElementById("post_btn");
// Variables constantes
const plasticGPerYear = 88_000_000_000; // Grams
// Variables modificables
let homeless = 662_520; // Based on statistics from the Dominican Republic in 2021
let plasticPerBrick = 500; // Grams
let gPerBottle = 20; // Grams
let emissionPerBottle = 82; // Grams
let bricksPerHouse = 5_000; // Bricks
let peoplePerHouse = 5;
let housesNeeded = Math.floor(homeless / peoplePerHouse); // Houses
let bricksNeeded = housesNeeded * bricksPerHouse; // Plastic bricks
let plasticNeeded = bricksNeeded * plasticPerBrick; // Grams
let followersRandomLimit = 1500;
// Data used during execution
let defaultSchema = {
emission: plasticGPerYear,
consented: 1,
recycled: 0,
homeless: homeless,
homelessSaved: 0,
houses: 0,
recycledTotal: 0,
plasticGRecycled: 0
};
let actualData = {};
checkData(); // Checking if the user has data
// Button events
recycleBtn.addEventListener("click", e => {
e.preventDefault();
recycle();
updateData();
render();
});
postBtn.addEventListener('click', e => {
e.preventDefault();
doPost();
updateData();
render();
});
Also see: Tab Triggers