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.
<svg hidden>
<symbol id="icon-delete" viewBox="0 0 24 24" >
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path> </symbol>
<symbol id="icon-bars" viewBox="0 0 24 24">
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8h16M4 16h16"></path> </symbol>
<symbol id="icon-envelope" viewBox="0 0 24 24" >
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path> </symbol>
</svg>
<div id="app">
<header class="bg-white flex flex-wrap px-4 pb-4 pt-1 border-b border-solid border-gray-400">
<div class="flex flex-grow items-center mr-2 mt-2">
<svg class="mr-1 h-8 w-8" xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7"></rect><rect x="14" y="3" width="7" height="7"></rect><rect x="14" y="14" width="7" height="7"></rect><rect x="3" y="14" width="7" height="7"></rect></svg>
<div>
<h1 class="text-lg font-semibold mb-0">Billfold</h1>
<p class="text-sm"><em>A graphical budget calculator</em></p>
</div>
</div>
<div class="flex mt-2">
<div class="flex flex-col">
<label class="text-xs">Monthly Income</label>
<input class="w-24 border border-solid border-gray-600 rounded-sm px-2 py-1" inputmode="numeric" placeholder="" v-model="monthlyIncome">
</div>
<div class="flex flex-col ml-4">
<label class="text-xs ">Other Money</label>
<input class="w-24 border border-solid border-gray-600 rounded-sm px-2 py-1 align-right" inputmode="numeric" placeholder="" v-model="otherIncome">
</div>
<div class="flex flex-col ml-4">
<label class="text-xs ">Bill Size</label>
<select class="border border-solid border-gray-600 rounded-sm px-2 py-1" v-model="blockSize">
<option>10</option>
<option>20</option>
<option>50</option>
<option>100</option>
<option>500</option>
<option>1000</option>
<option value="10000">10,000 (万)</option>
</select>
</div>
</div>
</header>
<main>
<section id="tutorial" v-if="envelopes.length < 2">
<div id="welcome" class="py-8 px-4 bg-cyan" v-if="!totalIncome || !blockSize || !envelopes.length">
<h2 class="text-3xl leading-none font-bold pb-4">Welcome to Billfold.</h2>
<ol class="pl-4">
<li :class="totalIncome? '' : 'list-decimal'">
<svg v-if="totalIncome" class="h-4 w-4 inline-block -ml-4 animation-pop" xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#00ebc7" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>
<strong>Enter your income</strong> and any other money you have lying around up above. 👆
</li>
<li :class="blockSize > 1? '' : 'list-decimal'">
<svg v-if="blockSize > 1" class="h-4 w-4 inline-block -ml-4 animation-pop" xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#00ebc7" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>
<strong>Set your bill size</strong> to your favorite government issued note. <code>100</code> is a good place to start. 💵
</li>
<li :class="envelopes.length? '' : 'list-decimal'">
<svg v-if="envelopes.length" class="h-5 w-5 inline-block -ml-4 animation-pop" xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="#00ebc7" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>
<strong>Create an envelope</strong> for each category of things you spend money on. 📩
</li>
</ol>
<div class="mt-4">
<button class="appearance-none border-none rounded-sm px-4 py-3 bg-pink text-white font-semibold" @click="quickStart">Use Quick Start Budget</button>
</div>
</div>
<p id="alert-nice" v-if="totalIncome && blockSize && envelopes.length" class="p-4 border-b border-solid border-gray-500">🙌 <strong>Nice Work!</strong> Create more envelopes, add blocks, and have blocks leftover! That's how you win at capitalism!</p>
</section>
<form v-if="totalIncome && blockSize > 1" v-on:submit.prevent="addNewEnvelope" class="p-4 flex w-full items-end">
<div class="flex flex-col flex-grow">
<label class="text-xs">Add envelope</label>
<input v-model="envelope.name" class="border border-solid border-gray-600 rounded-sm px-2 py-1 w-full" placeholder="Rent, Underwear, Tacos, etc"/>
</div>
<div class="flex flex-col flex-shrink mx-2 md:mx-4">
<label class="text-xs">Amount</label>
<input v-model="envelope.amount" type="number" inputmode="decimal" class="border border-solid border-gray-600 rounded-sm px-2 py-1 w-full" placeholder="540" />
</div>
<button type="submit" aria-label="Add Envelope" class="appearance-none border-none rounded-sm px-3 py-2 bg-pink text-white font-semibold">Add</button>
</form>
<draggable v-model="envelopes" @start="drag=true" @end="drag=false" handle=".handle">
<div v-for="(envelope, index) in envelopes" v-if="envelopes" class="px-4 bg-white animation-fadeIn" :key="index">
<header class="flex py-4 border-t border-solid border-gray-300 items-center w-100">
<span class="flex flex-grow items-center handle">
<svg class="mr-2 h-4 w-4 cursor-move"><use href="#icon-bars"></use></svg>
<input v-model="envelope.name" class="flex-grow" />
</span>
<span class="flex flex-shrink items-center justify-end">
<input v-model="envelope.amount" class="text-right" />
</span>
<button :aria-label="`Delete ${envelope.name}`" @click="deleteEnvelope( index )" class="ml-2 h-5 w-5"><svg class="trash w-5 h-5"><use href="#icon-delete"></use></svg></button>
</header>
<div class="block-grid pb-4" v-if="blocksForEnvelope(envelope.amount)">
<svg viewBox="0 0 150 100" class="animation-pop" height="100" width="150" v-for="block in blocksForEnvelope(envelope.amount)">
<rect class="bill" width="150" height="100" />
<text fill="currentColor" x=75 y=60 text-anchor="middle" font-size="2rem">{{ blockSize }}</text>
</svg>
</div>
</div>
</draggable>
<div id="unbudgeted" class="px-4 animation-fadeIn" v-if="totalIncome && blockSize > 1">
<header class="flex py-4 border-t border-solid border-gray-300 items-center">
<span class="flex flex-shrink items-center">
<svg class="mr-2 h-5 w-5"><use href="#icon-envelope"></use></svg>
Unbudgeted
</span>
<span class="flex flex-grow items-center justify-end">
{{ this.unbudgeted }}
<span class="ml-2">
<span v-if="this.unbudgeted > 0">😎</span>
<span v-if="this.unbudgeted == 0">😮</span>
<span v-if="this.unbudgeted < 0">😭</span>
</span>
</span>
</header>
<div class="block-grid pb-4" >
<svg viewBox="0 0 150 100" class="animation-pop" height="100" width="150" v-for="block in blocksForEnvelope(this.unbudgeted)">
<rect fill="#f2f4f6" stroke="#00214d" stroke-width="1" width="150" height="100" />
</svg>
</div>
</div>
</main>
</div>
// https://www.happyhues.co/palettes/10
body {
color: #333;
h1, h2, h3 {
color: #111
}
code {
color: #ff5470;
}
}
#app > header {
background: #f8f8f8;
border-bottom: 1px solid #001858!important;
}
.block-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
grid-gap: 0.5em;
svg {
max-width: 100%;
width: 100%;
height: auto;
}
}
.bill {
fill: #e3f6f5;
}
// https://www.happyhues.co/palettes/14
.bg-cyan {
background-color: #e3f6f5;
}
.bg-pink {
background-color: #F99;
color: #333;
}
// https://www.happyhues.co/palettes/2
#alert-nice {
background-color: #f2f4f6;
}
.animation-pop {
animation: pop 0.5s;
}
.animation-fadeIn {
animation: fadeIn 0.5s;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes pop {
0% { transform: scale(0.1) }
75% { transform: scale(1.1) }
100% { transform: scale(1) }
}
var quickStartBudget = [
{ name: "Housing", amount: 1200 },
{ name: "Transportation", amount: 650 },
{ name: "Groceries", amount: 250 },
{ name: "Personal & Family Care", amount: 50 },
{ name: "Health", amount: 300 },
{ name: "Restaurants", amount: 200 },
{ name: "Shopping & Entertainment", amount: 300 },
{ name: "Cash", amount: 150 },
{ name: "Education", amount: 100 },
{ name: "Finance", amount: 800 },
];
var app = new Vue({
el: '#app',
// data: {
// monthlyIncome: 0,
// otherIncome: 0,
// blockSize: 0,
// envelopes: [],
// envelope: {}
// },
// Test Data
data: {
monthlyIncome: 5400,
otherIncome: 0,
blockSize: 100,
envelopes: [],
envelope: {}
},
computed: {
totalIncome() {
return parseInt( this.monthlyIncome ) + parseInt( this.otherIncome )
},
totalBudgeted() {
if(!this.envelopes.length) return 0;
let total_budgeted = this.envelopes.reduce( (sum, obj) => {
return {
amount: parseFloat(sum.amount) + parseFloat(obj.amount)
}
}).amount;
return total_budgeted;
},
unbudgeted() {
return this.totalIncome - this.totalBudgeted;
},
},
methods: {
quickStart() {
this.envelopes = quickStartBudget;
},
blocksForEnvelope(amount) {
if( parseInt(amount) < 0) {
return 0;
}
let tbs = Math.floor( parseInt(amount) / parseInt(this.blockSize) );
return tbs;
},
addNewEnvelope() {
this.envelopes.push({
name: this.envelope.name,
amount: this.envelope.amount
});
this.envelope = {}
},
deleteEnvelope: function( index ) {
if (confirm(`Delete "${this.envelopes[index].name}" envelope?`)) {
this.envelopes.splice(index, 1);
}
}
}
})
Also see: Tab Triggers