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 id="container">
<div class="cover">
<h1>Tech1101 <br />Calculator</h1>
<!-- First is just instructions for user input -->
<p id="first" class='first-line'>Only use these characters</p>
<p class="minus-padding"> 0-9 , * , / , - , + , = </p>
</div>
<div class="calculator">
<section class="head">
<div id="displayField">
<span class="blinking-cursor">|</span>
<span id="equals" class="numbers"></span>
</div>
</section>
<div class="btnSection">
<div class="row row-top" id="center clear">
<div id="allClear" class="center col dub clear">Clear All</div>
<div id="clearOne" class="center col dub clear">Clear </div>
</div>
<div class="row row1">
<div id="seven" class="center col num solo" data-value="7">7</div>
<div id="eight" class="center col num solo" data-value="8">8</div>
<div id="nine" class="center col num solo" data-value="9">9</div>
<div id="divide" class="center col solo symbols" data-value="/">/</div>
</div>
<div class="row row2">
<div id="four" class="center col num solo" data-value="4">4</div>
<div id="five" class="center col num solo" data-value="5">5</div>
<div id="six" class="center col num solo" data-value="6">6</div>
<div id="multiply" class="center col solo symbols" data-hamburger="*">*</div>
</div>
<div class="row row3">
<div id="one" class="center col num solo" data-value="1">1</div>
<div id="two" class="center col num solo" data-value="2">2</div>
<div id="three" class="center col num solo" data-value="3">3</div>
<div id="subtract" class="center col solo symbols" data-value="-">-</div>
</div>
<div class="row">
<div id="zero" class="center col num dub" data-value="0">0</div>
<div id="decimal" class="center col solo symbols" data-value=".">.</div>
<div id="add" class="center col solo symbols" data-value="+">+</div>
</div>
<div class="row">
<div id="equal" class="col dub red" data-value="=">=</div>
</div>
</div>
</div>
</div>
* { margin: 0px; padding: 0; box-sizing: border-box; }
html, body {
background-color: whitesmoke;
font-size: 25px;
font-family: Helvetica, sans-serif;
font-weight: 900;
position: relative;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
#container {
display: flex;
flex-direction: column;
max-width: 300px;
}
.cover {
text-align: center;
}
.cover > h1 {
padding-top: 10px;
border-top: 2px black solid;
margin-top: 30px;
font-size: 1.6rem;
color: rgba(0,0,0,0.6);
text-shadow: 3px 3px 3px rgba(255,255,255,0.8);
}
.cover > p {
font-size: 1rem;
}
p:nth-child(2), #second {
color: whitesmoke;
margin-top: 6px;
margin-bottom: 3px;
background-color: red;
padding: 5px 0;
text-shadow: 1px 1px 2px #191919;
}
.minus-padding {
margin-bottom: -50px;
padding: 5px 0;
color: rgba(0,0,0,0.6);
text-shadow: 3px 3px 3px rgba(255,255,255,0.8);
border-bottom: 2px black solid;
}
.calculator {
//display: flex;
flex-direction: column;
justify-content: center;
margin: 3em 0;
width: 100%;
border-radius: 10px;
}
.head, .btnSection {
display: flex;
width: 100%;
flex-direction: column;
}
#second {
display: none;
}
#displayField {
height: 50px;
font-size: 1rem;
padding: 10px;
padding-bottom: 30px;
text-align: right;
border: 1px black solid;
border-radius: 10px 10px 0 0;
box-shadow: 1px 1px 3px 1px rgba(0,0,0,0.3),
-1px -1px 3px 1px rgba(0,0,0,0.3);
}
.row {
display: flex;
height: 50px;
}
.row > .red {
border-radius: 0 0 10px 10px;
height: 100px;
background-color: red;
color: white;
font-size: 3em;
text-shadow: 2px 2px 5px black;
}
.col {
text-align: center;
border: 1px black solid;
//margin: 2px;
}
.dub {
flex-grow: 3;
}
.solo {
flex-grow: 1;
}
.symbols {
flex-basis: 50px;
color: whitesmoke;
background-color: darkblue;
text-shadow: 2px 2px 4px #191919;
}
.num {
background-color: #209cee;
color: whitesmoke;
text-shadow: 1px 1px 4px #191919;
}
.clear {
background-color: lightgreen;
color: whitesmoke;
text-shadow: 1px 1px 4px black;
}
.center { padding-top: 8px; }
.blinking-cursor {
font-weight: 200;
line-height: 30px;
animation: 3s blink step-end infinite;
}
@keyframes "blink" {
from, to {
color: transparent;
}
50% {
color: black;
}
}
//Input!!
//document.querySelectorAll(cssSelect)
//document.querySelector(cssSelect)
const nine = getSelector('#nine')
const eight = getSelector('#eight')
const seven = getSelector('#seven')
const six = getSelector('#six')
const five = getSelector('#five')
const four = getSelector('#four')
const three = getSelector('#three')
const two = getSelector('#two')
const one = getSelector('#one')
const zero = getSelector('#zero')
// Operators
const subtract = getSelector('#subtract')
const add = getSelector('#add')
const divide = getSelector('#divide')
const multiply = getSelector('#multiply')
/* Fix multiply using regex - replace("X","*") */
const decimal = getSelector('#decimal')
const equal = getSelector('#equal')
// Output!!
let equals = getSelector('#equals')
// Clears
const allClear = getSelector('#allClear')
const clearOne = getSelector('#clearOne')
// Test Event Listner Builder
/* */
function buildListner (id){
id.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + id.innerHTML;
})
}// Could use an array as well? Done! See below
const numbers = [zero,one,two,three,four,five,six,seven,eight,nine]
numbers.forEach(number => buildListner(number))
/* Version 2
function buildListner (id){
id.addEventListener('click', buildListnerResult)
}
function buildListnerResult (id){
equals.innerHTML = equals.innerHTML + id.innerHTML;
}
//version 3 - use array
operators.forEach(operator => buildListner(operator))
*/
/* // Version 1: Number Listeners
buildListner(zero)
buildListner(one)
buildListner(two)
buildListner(three)
buildListner(four)
buildListner(five)
buildListner(six)
buildListner(seven)
buildListner(eight)
buildListner(nine)
*/
/* zero.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + zero.innerHTML;
})
one.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + one.innerHTML;
})
two.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + two.innerHTML;
})
three.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + three.innerHTML;
})
four.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + four.innerHTML;
})
five.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + five.innerHTML;
})
six.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + six.innerHTML;
})
seven.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + seven.innerHTML;
})
eight.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + eight.innerHTML;
})
nine.addEventListener('click', function() {
equals.innerHTML = equals.innerHTML + nine.innerHTML;
})
*/
// Operator Listners
// Try with Array
const operators = [divide, multiply, subtract, decimal, add]
operators.forEach(operator => buildListner(operator))
equal.addEventListener('click', function() {
equals.innerHTML = eval(equals.innerHTML);
})
// Clear output
allClear.addEventListener('click', clearAllData)
clearOne.addEventListener('click', clearOneData)
//Clear data when called
function clearAllData(){
equals.innerHTML='';
}
function clearOneData (){
let str = equals.innerHTML
shrinkString(str)
}
function shrinkString (val) {
equals.innerHTML = val.substr(0,val.length-1)
}
// Helper Functions for Listners/Selectors
// Use for Numbers & Operators
function getAllSelectors (cssSelect) {
return document.querySelectorAll(cssSelect)
}
// Use for symbols and Utilities on Calculator
function getSelector(cssSelect){
return document.querySelector(cssSelect)
}
Also see: Tab Triggers