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.
<html>
<head>
<title>Apple Calculator</title>
</head>
<body>
<div class="wrapper">
<div class="calc-body">
<div class="readout">
<span class="value" id="output">0</span>
</div>
<div id="button-panel" class="buttons">
<div class="left-side">
<button id="f-mp" class="small">m+</button>
<button id="f-mm" class="small">m-</button>
<button id="f-mc" class="small">mc</button>
<button id="f-mr" class="small">mr</button>
<button id="n-7" class="big">7</button>
<button id="n-8" class="big">8</button>
<button id="n-9" class="big">9</button>
<button id="n-4" class="big">4</button>
<button id="n-5" class="big">5</button>
<button id="n-6" class="big">6</button>
<button id="n-1" class="big">1</button>
<button id="n-2" class="big">2</button>
<button id="n-3" class="big">3</button>
<button id="n-0" class="big">0</button>
<button id="n-p" class="big">.</button>
<button id="f-c" class="big">c</button>
</div>
<div class="right-side">
<button id="f-d" class="small">÷</button>
<button id="f-t" class="small">×</button>
<button id="f-m" class="small">-</button>
<button id="f-a" class="small">+</button>
<button id="f-e" class="small tall">=</button>
</div>
</div>
</div>
</div>
</html>
/* Welcome to Compass.
* In this file you should write your main styles. (or centralize your imports)
* Import this file using the following HTML or equivalent:
* <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" /> */
/* line 17, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font: inherit;
font-size: 100%;
vertical-align: baseline;
}
/* line 22, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
html {
line-height: 1;
}
/* line 24, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
ol, ul {
list-style: none;
}
/* line 26, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
table {
border-collapse: collapse;
border-spacing: 0;
}
/* line 28, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
caption, th, td {
text-align: left;
font-weight: normal;
vertical-align: middle;
}
/* line 30, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
q, blockquote {
quotes: none;
}
/* line 103, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
q:before, q:after, blockquote:before, blockquote:after {
content: "";
content: none;
}
/* line 32, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
a img {
border: none;
}
/* line 116, ../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary {
display: block;
}
/* line 9, ../sass/screen.scss */
body {
background-color: #545454;
background-size: 13px 13px, 13px 13px;
background-position: -2px -2px, -2px -2px;
background-image: -moz-linear-gradient(#474747 1px, transparent 1px), -moz-linear-gradient(0, #474747 1px, transparent 1px);
background-image: -webkit-linear-gradient(#474747 1px, transparent 1px), -webkit-linear-gradient(0, #474747 1px, transparent 1px);
background-image: -ms-linear-gradient(#474747 1px, transparent 1px), -ms-linear-gradient(0, #474747 1px, transparent 1px);
}
/* line 17, ../sass/screen.scss */
div, button, span {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
/* line 21, ../sass/screen.scss */
.wrapper {
width: 156px;
height: 234px;
position: relative;
margin: 50px;
}
/* line 29, ../sass/screen.scss */
.wrapper .calc-body {
width: 100%;
height: 100%;
padding: 6px;
margin: 0;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-ms-border-radius: 10px;
-o-border-radius: 10px;
border-radius: 10px;
-webkit-box-shadow: 0 3px 8px 0px rgba(0, 0, 0, 0.7);
-moz-box-shadow: 0 3px 8px 0px rgba(0, 0, 0, 0.7);
box-shadow: 0 3px 8px 0px rgba(0, 0, 0, 0.7);
background-image: -webkit-linear-gradient(#fd823a, #fc6a27);
background-image: -moz-linear-gradient(#fd823a, #fc6a27);
}
/* line 38, ../sass/screen.scss */
.wrapper .calc-body .readout {
-webkit-box-shadow: inset 0 2px 3px 0px rgba(0, 0, 0, 0.3);
-moz-box-shadow: inset 0 2px 3px 0px rgba(0, 0, 0, 0.3);
box-shadow: inset 0 2px 3px 0px rgba(0, 0, 0, 0.3);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
background-image: -webkit-linear-gradient(#b6dcf0, #b6dcf0 46%, #a2d3ee 46%, #acd8f0);
background-image: -moz-linear-gradient(#b6dcf0, #b6dcf0 46%, #a2d3ee 46%, #acd8f0);
width: 100%;
height: 35px;
margin-bottom: 6px;
background-color: #a9d6f0;
}
/* line 47, ../sass/screen.scss */
.wrapper .calc-body .readout .value {
font-family: Arial;
color: #434343;
padding: 10px;
padding-top: 15px;
display: block;
width: 100%;
height: 100%;
text-align: right;
}
/* line 60, ../sass/screen.scss */
.wrapper .calc-body .buttons {
width: 100%;
height: 181px;
background-image: -webkit-linear-gradient(#cacaca, #bbbbbb);
background-image: -moz-linear-gradient(#cacaca, #bbbbbb);
-webkit-box-shadow: inset 0 1px 1px 0px rgba(0, 0, 0, 0.3);
-moz-box-shadow: inset 0 1px 1px 0px rgba(0, 0, 0, 0.3);
box-shadow: inset 0 1px 1px 0px rgba(0, 0, 0, 0.3);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-ms-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
/* line 68, ../sass/screen.scss */
.wrapper .calc-body .buttons .left-side {
padding: 3px;
width: 115px;
float: left;
}
/* line 74, ../sass/screen.scss */
.wrapper .calc-body .buttons .right-side {
padding: 3px;
width: 29px;
float: left;
}
/* line 79, ../sass/screen.scss */
.wrapper .calc-body .buttons .right-side button.small:not(:first-child) {
margin-top: 6px;
}
/* line 85, ../sass/screen.scss */
.wrapper .calc-body .buttons button {
-webkit-box-shadow: 0 1px 2px 0px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 0 1px 2px 0px rgba(0, 0, 0, 0.4);
box-shadow: 0 1px 2px 0px rgba(0, 0, 0, 0.4);
background-image: -webkit-linear-gradient(white, #e9e9e9);
outline: none;
text-align: center;
border: 2px solid #fff;
display: inline-block;
font-family: Arial;
font-weight: bold;
color: #868686;
-webkit-border-radius: 50% 50%;
-moz-border-radius: 50% / 50%;
border-radius: 50% / 50%;
}
/* line 98, ../sass/screen.scss */
.wrapper .calc-body .buttons button:active {
background-image: -webkit-linear-gradient(#e9e9e9, white);
}
/* line 102, ../sass/screen.scss */
.wrapper .calc-body .buttons button.active {
background-image: -webkit-linear-gradient(#fdb474, #fd9030);
background-image: -moz-linear-gradient(#fdb474, #fd9030);
color: white;
}
/* line 107, ../sass/screen.scss */
.wrapper .calc-body .buttons button.small {
margin: 1px;
width: 22px;
height: 22px;
font-size: 8px;
padding: 0;
}
/* line 116, ../sass/screen.scss */
.wrapper .calc-body .buttons button.tall {
height: 54px;
-webkit-border-radius: 11px 11px;
-moz-border-radius: 11px / 11px;
border-radius: 11px / 11px;
}
/* line 121, ../sass/screen.scss */
.wrapper .calc-body .buttons button.big {
width: 33px;
height: 33px;
margin-top: 4px;
border: 3px solid #fff;
}
(function(){
var display = document.getElementById("output");
var operatorFn = null;
var RegA = 0;
var RegB = 0;
var resultMode = false;
var screenText = "";
var screenIsDecimal = false;
var activeButton = null;
var bp = document.getElementById("button-panel");
bp.addEventListener("click", function(event){
var target = event.target;
if(target.tagName === "BUTTON"){
var fn = target.getAttribute("id").split("-");
if(fn[0] === "n"){
number(fn[1]);
} else {
switch(fn[1]){
case "c":
reset(true);
break;
case "t":
case "m":
case "a":
case "d":
operate(fn[1], target);
break;
case "e":
equals();
break;
}
}
}
}, true);
function buttonShowActive(button){
// First deactivate any other button
buttonsShowInactive();
activeButton = button;
addClass(button, "active");
}
function buttonsShowInactive(){
if(activeButton){
removeClass(activeButton, "active");
activeButton = null;
}
}
/**
* Adds a class to the given object
* @param {[type]} object [description]
* @param {[type]} cls [description]
*/
function addClass(object, cls){
object.className += " " + cls;
}
function removeClass(object, cls){
object.className = object.className.replace(cls, "").replace(/\s+/g, ' ').trim();
}
function operate(method, button){
console.log("operate");
buttonShowActive(button);
operatorFn = method;
if(resultMode){
console.log("Result mode");
RegB = 0;
dumpReg();
resultMode = false;
} else {
if(!RegA){
RegA = +screenText;
} else {
RegB = +screenText;
calculate();
}
}
// Clear out the input
screenText = "";
}
function output(value){
value = "" + value;
display.innerHTML = value.substring(0, 14);
}
function reset(zero){
resultMode = false;
screenIsDecimal = false;
RegA = 0;
RegB = 0;
if (zero)
screenText = "0";
else
screenText = "";
operatorFn = null;
buttonsShowInactive();
output(screenText);
}
function number(n){
if(resultMode){
reset();
console.log("resuilts");
}
buttonsShowInactive();
if(n === "p"){
if(!screenIsDecimal){
screenIsDecimal = true;
output(screenText += ".");
}
} else {
if(+n != 0 && +screenText == 0 && screenText != ".")
screenText = "";
if(+n == 0 && +screenText == 0)
screenText = "0";
else
screenText += n;
output(screenText);
}
}
function equals(){
resultMode = true;
RegB = +screenText;
calculate();
}
function dumpReg(){
console.log("RegA "+RegA);
console.log("RegB "+RegB);
}
function calculate(){
console.log("Calculating...");
dumpReg();
switch(operatorFn){
case "t":
RegA = RegA * RegB;
break;
case "m":
RegA = RegA - RegB;
break;
case "d":
RegA = RegA / RegB;
break;
case "a":
RegA = RegA + RegB;
break;
// do nothing if we have no operator
default:
return;
break;
}
dumpReg();
output(RegA);
}
})();
Also see: Tab Triggers