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 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.
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="container-fluid">
<div class="row d-flex flex-column vh-100 py-5">
<div class="col d-flex align-items-center py-3 position-relative" id="displayArea">
<div id="errors" class="position-absolute text-center px-3" style="left: 0;right: 0;">
<p id="noblank" class="d-none display-1 text-uc">You should clear a cell</p>
<p id="manyblank" class="d-none display-1 text-uc">Too many blanks there guy</p>
<p id="notnumber" class="d-none display-1 text-uc">Your numbers are a failure</p>
<p id="zero" class="d-none display-1 text-uc">You tryin'a divide by zero</p>
<p id="displayFactor" class="d-none"></p>
</div>
<div class="mx-auto" id="displayareacont" style="width: 480px; height: 252px;">
<div class="position-absolute" id="red" style="width: 480px; height: 252px;"></div>
<div class="position-absolute" id="blue" style="width: 280px; height: 147px;"></div>
</div>
</div>
<div class="col flex-grow-0" id="controls">
<form role="calculate" class="container" novalidate>
<div class="row mx-n1">
<div class="col px-1">
<input type="text" id="a" value="1200" autocomplete="off" onkeydown="javascript: return event.which === 190 || event.keyCode === 8 || event.keyCode === 9 || event.keyCode === 46 ? true : !isNaN(Number(parseInt(event.key)))" onClick="this.setSelectionRange(0, this.value.length)" pattern="[0-9]*" class="w-100 mb-2 px-2 py-1">
</div>
<div class="col px-1">
<input type="text" id="b" value="630" autocomplete="off" onkeydown="javascript: return event.which === 190 || event.keyCode === 8 || event.keyCode === 9 || event.keyCode === 46 ? true : !isNaN(Number(parseInt(event.key)))" onClick="this.setSelectionRange(0, this.value.length)" pattern="[0-9]*" class="w-100 mb-2 px-2 py-1">
</div>
</div>
<div class="row mx-n1">
<div class="col px-1">
<input type="text" id="c" value="700" autocomplete="off" onkeydown="javascript: return event.which === 190 || event.keyCode === 8 || event.keyCode === 9 || event.keyCode === 46 ? true : !isNaN(Number(parseInt(event.key)))" onClick="this.setSelectionRange(0, this.value.length)" pattern="[0-9]*" class="w-100 mb-2 px-2 py-1">
</div>
<div class="col px-1">
<input type="text" id="d" value="" autocomplete="off" onkeydown="javascript: return event.which === 190 || event.keyCode === 8 || event.keyCode === 9 || event.keyCode === 46 ? true : !isNaN(Number(parseInt(event.key)))" onClick="this.setSelectionRange(0, this.value.length)" pattern="[0-9]*" class="w-100 mb-2 px-2 py-1">
</div>
</div>
<div class="row">
<div class="col">
<div class="form-check mb-2">
<input class="form-check-input bg-dark" type="checkbox" id="solveD" name="solveD" checked>
<label class="form-check-label" for="solveD">Always solve for bottom-right position</label>
</div>
</div>
</div>
<div class="row">
<div class="col">
<button class="btn btn-dark w-100 mb-2" type="button" id="calc" name="calculate">Calculate</button>
</div>
</div>
</form>
</div>
</div>
</div>
body {
overflow: hidden;
}
.hide {
display: none;
}
.text-uc {
text-transform: uppercase;
}
/* DISPLAY AREA */
#red,
#blue,
#displayareacont {
-webkit-transition: all 1s;
transition: all 1s;
}
#displayareacont {
width: 20px;
height: 20px;
display: block;
opacity: 1;
}
#displayareacont.d-none {
opacity: 0;
display: block !important;
}
#red,
#blue {
height: 20px;
width: 20px;
background-blend-mode: multiply;
}
#red,
#a,
#b {
border: solid 1px #19191a;
background: rgba(255, 0, 0, 0.2);
}
#blue,
#c,
#d {
border: dashed 1px #19191a;
background: rgba(0, 0, 255, 0.2);
}
$("#calc").click(function () {
var prop = [0, 1, 2, 3], // a/b=c/d
numInvalid = 0, // clear error codes
numBlanks = 0,
zeroError = 0,
displayH = $("#displayArea").height(), //get display area h/w
displayW = $("#displayArea").width(),
displayFactor = 1; //display factor
// assign values to a/b=c/d
prop[0] = $("#a").val();
prop[1] = $("#b").val();
prop[2] = $("#c").val();
prop[3] = $("#d").val();
// clear bottom right if checked
if ($("#solveD").is(":checked")) {
prop[3] = "";
}
// check proportions for invalid number, too many blanks, zeroes -- log that error!
for (var i = 0; i < prop.length; i++) {
if (isNaN(prop[i])) {
numInvalid = true;
}
if (prop[i] == "") {
numBlanks++;
}
if (prop[i] == 0 && prop[i].length != 0) {
zeroError = true;
}
}
// check for errors... display the error
$("#manyblank,#noblank,#notnumber,#zero,#displayFactor").addClass("d-none");
if (numBlanks < 1) {
$("#noblank").removeClass("d-none");
} else if (numBlanks > 1) {
$("#manyblank").removeClass("d-none");
} else if (numInvalid) {
$("#notnumber").removeClass("d-none");
} else if (zeroError) {
$("#zero").removeClass("d-none");
} else {
$("#displayareacont").removeClass("d-none");
// if no errors... figure out which one was blank and solve
if (prop[0] == "") {
prop[0] = Math.round((prop[2] / prop[3]) * prop[1] * 1000) / 1000;
$("#a").val(prop[0]);
} else if (prop[1] == "") {
prop[1] = Math.round((prop[3] / prop[2]) * prop[0] * 1000) / 1000;
$("#b").val(prop[1]);
} else if (prop[2] == "") {
prop[2] = Math.round((prop[0] / prop[1]) * prop[3] * 1000) / 1000;
$("#c").val(prop[2]);
} else if (prop[3] == "") {
prop[3] = Math.round((prop[1] / prop[0]) * prop[2] * 1000) / 1000;
$("#d").val(prop[3]);
}
// See if we need to shrink the display factor for the red and blue boxes
if (prop[1] > displayH || prop[3] > displayH || prop[0] > displayW || prop[2] > displayW) {
displayFactor = Math.min(
displayH / Math.max(prop[1], prop[3]),
displayW / Math.max(prop[0], prop[2])
);
$("#displayFactor")
.removeClass("d-none")
.html("Displaying at ~" + Math.round(displayFactor * 10000) / 100 + "%")
.addClass("error");
}
// Update the red and blue boxes with.
$("#red").css({
width: prop[0] * displayFactor,
height: prop[1] * displayFactor
});
$("#blue").css({
width: prop[2] * displayFactor,
height: prop[3] * displayFactor
});
$("#displayareacont").css({
width: Math.max(prop[0], prop[2]) * displayFactor,
height: Math.max(prop[1], prop[3]) * displayFactor
});
}
});
Also see: Tab Triggers