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 URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
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.
If the stylesheet 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 CSS 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.
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="main">
<div class="top">
<div class="top2">
<a class="mainlogo">XASIO</a>
<a class="logo">fg-81RS PLUS</a>
<a class="logo2">natural vcm</a>
</div>
<div class="top1">
<div class = "solar">
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
</div>
</div>
</div>
<textarea rows="4" cols="22" class="screen">
</textarea>
<div class="controls">
<div class="button-placeholder">
<a class="button">7</a>
<a class="button">4</a>
<a class="button">1</a>
<a class="button">0</a>
</div>
<div class = "button-placeholder">
<a class="button">8</a>
<a class="button">5</a>
<a class="button">2</a>
<a class="button">.</a>
</div>
<div class = "button-placeholder">
<a class="button">9</a>
<a class="button">6</a>
<a class="button">3</a>
<a class="operation"></a>
</div>
<div class = "button-placeholder">
<a class="operation" id="division">/</a>
<a class="operation" id="multiply">x</a>
<a class="operation" id="plus">+</a>
<a class="operation" id="minus">-</a>
</div>
<div class = "button-placeholder">
<a class="operation" id="ac">ac</a>
<a class="operation"></a>
<a class="operation"></a>
<a class="operation" id="equals">=</a>
</div>
</div>
</div>
@import url('https://fonts.googleapis.com/css?family=VT323');
@import url('https://fonts.googleapis.com/css?family=Orbitron');
.main {
width: 250px;
height: 380px;
border-radius: 30px;
border: 3px solid #b2b2b2;
box-shadow: 0px 0px 25px 0px black;
background-color:#494949;
display:flex;
flex-direction:column;
position: absolute;
}
.top {
align-self:center;
display: flex;
width:100%;
}
.top1 {
flex:1.5;
}
.top2 {
display:flex;
flex:1;
flex-direction:column;
justify-content:flex-end;
align-items:flex-start;
}
.mainlogo {
margin-left:30px;
color:white;
margin-bottom:4px;
font-size:14px;
}
.logo {
color:white;
font-size:8px;
margin-left:30px;
}
.logo2 {
color:#a35e72;
font-size:8px;
margin-left:30px;
}
.solar {
width:120px;
height:40px;
background-color:#4e332c;
border-radius:10px;
box-shadow: inset 0px 0px 8px 0px #333333;
margin-top:15px;
display:flex;
margin-left:5px;
}
.line {
border:1px solid #1c1c1c;
border-top:none;
border-bottom:none;
width:35%;
height:40px;
}
.line:nth-child(1) {
border-left:none;
}
.line:nth-child(3) {
border-right:none;
}
.screen {
width:200px;
height:100px;
background-color:#d4e2e1;
border-radius:10px;
align-self: center;
margin-top:10px;
box-shadow: inset 0px 0px 7px 0px #595959;
box-sizing:border-box;
padding:10px;
font-size:28px;
font-family: 'VT323', monospace;
}
.controls {
display:flex;
flex-direction:row;
margin-top:30px;
margin-left:auto;
margin-right:auto;
width:85%;
}
.button-placeholder {
display:flex;
flex-direction:column;
width:20%;
}
.button, .operation {
user-select:none;
width:90%;
height:20px;
margin-bottom:5px;
padding-top:4px;
padding-bottom:4px;
background-color:#333333;
color:white;
/*border-top: 2px solid #7c7c7c;
border-left:1px solid grey;
border-right:1px solid grey;*/
box-shadow: 0px 3px #7c7c7c;
text-align:center;
border-radius:10px;
cursor:default;
font-family: 'Orbitron', sans-serif;
font-size:14px;
}
.button:active, .operation:active {
box-shadow: 0px 1px #878787;
transform: translateY(2px);
cursor:default;
}
let result;
let operation = [];//allready present as param
let index = 0;
let numberIndex = 0; //not needed
let operationArr;
let numberArr;
let subArr;
let operationIndex;
function divide() {
if (operation.indexOf("/") > -1) {
while (operation.indexOf("/") !== -1) {
operationIndex = operation.indexOf("/");
subArr = operation.slice(operationIndex - 1, operationIndex + 2);
operationArr = subArr.filter(element => element === "+" || element === "-" || element === "/" || element === "*");
numberArr = subArr.filter(element => element !== "+" && element !== "-" && element !== "*" && element !== "/");
acc2 = numberArr.reduce(parser);
operation.splice(operationIndex - 1, 3, acc2);
index = 0;
}
}
}
function multiply() {
if (operation.indexOf("*") > -1) {
while (operation.indexOf("*") !== -1) {
operationIndex = operation.indexOf("*");
console.log("executor entered for * at index: ", operationIndex);
subArr = operation.slice(operationIndex - 1, operationIndex + 2);
operationArr = subArr.filter(element => element === "+" || element === "-" || element === "/" || element === "*");
numberArr = subArr.filter(element => element !== "+" && element !== "-" && element !== "*" && element !== "/");
acc2 = numberArr.reduce(parser);
operation.splice(operationIndex - 1, 3, acc2);
index = 0;
console.log("acc2: ", acc2);
console.log("subArr: " + subArr);
console.log("numberArr: " + numberArr);
console.log("operationArr: " + operationArr);
console.log("operation: " + operation);
}
}
}
function add() {
if (operation.indexOf("+") > -1) {
while (operation.indexOf("+") !== -1) {
operationIndex = operation.indexOf("+");
console.log("executor entered for + at index: ", operationIndex);
subArr = operation.slice(operationIndex - 1, operationIndex + 2);
operationArr = subArr.filter(element => element === "+" || element === "-" || element === "/" || element === "*");
numberArr = subArr.filter(element => element !== "+" && element !== "-" && element !== "*" && element !== "/");
acc2 = numberArr.reduce(parser);
operation.splice(operationIndex - 1, 3, acc2);
index = 0;
console.log("acc2: ", acc2);
console.log("subArr: " + subArr);
console.log("numberArr: " + numberArr);
console.log("operationArr: " + operationArr);
console.log("operation: " + operation);
}
}
}
function subtract() {
if (operation.indexOf("-") > -1) {
while (operation.indexOf("-") !== -1) {
operationIndex = operation.indexOf("-");
console.log("executor entered for - at index: ", operationIndex);
subArr = operation.slice(operationIndex - 1, operationIndex + 2);
operationArr = subArr.filter(element => element === "+" || element === "-" || element === "/" || element === "*");
numberArr = subArr.filter(element => element !== "+" && element !== "-" && element !== "*" && element !== "/");
acc2 = numberArr.reduce(parser);
operation.splice(operationIndex - 1, 3, acc2);
index = 0;
console.log("acc2: ", acc2);
console.log("subArr: " + subArr);
console.log("numberArr: " + numberArr);
console.log("operationArr: " + operationArr);
console.log("operation: " + operation);
}
}
}
function parser(acc, element) {
console.log("accumalator: ", acc, " element: ", element, " operation: ", operationArr[index], " index: ", index);
if (operationArr[index] === "/") {
acc = parseFloat(acc) / parseFloat(element);
index++;
return acc;
}
if (operationArr[index] === "*") {
acc = parseFloat(acc) * parseFloat(element);
index++;
return acc;
}
if (operationArr[index] === "+") {
acc = parseFloat(acc) + parseFloat(element);
index++;
return acc;
}
if (operationArr[index] === "-") {
acc = parseFloat(acc) - parseFloat(element);
index++;
return acc;
}
}
$(".button").on("click", function() {
if ($(this).text() === ".") {
if (operation[numberIndex][operation[numberIndex].length - 1] === "." || operation[numberIndex].indexOf(".") > -1) {
return;
}
}
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += $(this).text();
console.log(operation);
$(".screen").html(operation);
});
// ADDITION OPERATOR
$("#plus").on("click", function() {
if (operation.length !== 0) {
if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
numberIndex += 2;
operation.push("+");
console.log(operation);
$(".screen").html(operation);
}
}
});
// MINUS OPERATOR
$("#minus").on("click", function() {
if (operation.length !== 0) {
if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
numberIndex += 2;
operation.push("-");
console.log(operation);
$(".screen").html(operation);
}
}
});
// MULTIPLICATION OPERATOR
$("#multiply").on("click", function() {
if (operation.length != 0) {
if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
numberIndex += 2;
operation.push("*");
console.log(operation);
$(".screen").html(operation);
}
}
});
// DIVISION OPERATOR
$("#division").on("click", function() {
if (operation.length != 0) {
if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
numberIndex += 2;
operation.push("/");
console.log(operation);
$(".screen").html(operation);
}
}
});
// EQUAL OPERATOR
$("#equals").on("click", function() {
divide();
multiply();
add();
subtract();
result = operation;
console.log("result:", result);
$(".screen").html(result);
operation = [];
operation[0] = result[0];
index = 0;
numberIndex = 0;
});
// HELPER OPERATORS
$("#ac").on("click", function() {
operation = [];
index = 0;
numberIndex = 0;
$(".screen").html("");
console.log("cleared operation:", operation);
});
$(document).keydown(function(e) {
switch (e.which) {
case 96:
case 48:
{
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += "0";
console.log(operation);
$(".screen").html(operation);
}
break;
case 97:
case 49:
{
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += "1";
console.log(operation);
$(".screen").html(operation);
}
break;
case 98:
case 50:
{
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += "2";
console.log(operation);
$(".screen").html(operation);
}
break;
case 99:
case 51:
{
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += "3";
console.log(operation);
$(".screen").html(operation);
}
break;
case 100:
case 52:
{
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += "4";
console.log(operation);
$(".screen").html(operation);
}
break;
case 101:
case 53:
{
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += "5";
console.log(operation);
$(".screen").html(operation);
}
break;
case 102:
case 54:
{
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += "6";
console.log(operation);
$(".screen").html(operation);
}
break;
case 103:
case 55:
{
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += "7";
console.log(operation);
$(".screen").html(operation);
}
break;
case 104:
case 56:
{
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += "8";
console.log(operation);
$(".screen").html(operation);
}
break;
case 105:
case 57:
{
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += "9";
console.log(operation);
$(".screen").html(operation);
}
break;
case 187:
case 13:
{
divide();
multiply();
add();
subtract();
result = operation;
console.log("result:", result);
$(".screen").html(result);
operation = [];
operation[0] = result;
index = 0;
numberIndex = 0;
}
break;
case 107:
{
if (operation.length !== 0) {
if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
numberIndex += 2;
operation.push("+");
console.log(operation);
$(".screen").html(operation);
}
}
}
break;
case 109:
{
if (operation.length != 0) {
if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
numberIndex += 2;
operation.push("-");
console.log(operation);
$(".screen").html(operation);
}
}
}
break;
case 106:
{
if (operation.length != 0) {
if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
numberIndex += 2;
operation.push("*");
console.log(operation);
$(".screen").html(operation);
}
}
}
break;
case 111:
{
if (operation.length != 0) {
if (operation[operation.length - 1] !== "+" && operation[operation.length - 1] !== "-" && operation[operation.length - 1] !== "*" && operation[operation.length - 1] !== "/") {
numberIndex += 2;
operation.push("/");
console.log(operation);
$(".screen").html(operation);
}
}
}
break;
case 8:
case 46:
{
operation = [];
index = 0;
numberIndex = 0;
$(".screen").html("");
console.log("cleared operation:", operation);
}
break;
case 110:
case 190:
{
if (operation[numberIndex][operation[numberIndex].length - 1] === "." || operation[numberIndex].indexOf(".") > -1) {
return;
}
if (operation[numberIndex] === undefined) {
operation.push("");
}
operation[numberIndex] += ".";
console.log(operation);
$(".screen").html(operation);
}
default:
return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
Also see: Tab Triggers