cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="calculator">

  <div class="screen">
    <div class="screen-inner output"></div>
  </div>

  <div class="controls noselect">

    <div class="control-quarter">
      <div class="control all-clear" onclick="clearAll();">AC</div>
      <div class="control seven" onclick="addToInput(7);">7</div>
      <div class="control four" onclick="addToInput(4);">4</div>
      <div class="control one" onclick="addToInput(1);">1</div>
      <div class="control zero" onclick="addToInput(0);">0</div>
    </div>
    <div class="control-quarter">
      <div class="control clear-entry" onclick="clearInput();">CE</div>
      <div class="control eight" onclick="addToInput(8);">8</div>
      <div class="control five" onclick="addToInput(5);">5</div>
      <div class="control two" onclick="addToInput(2);">2</div>
      <div class="control decimal" onclick="addDecimalToInput();">.</div>
    </div>
    <div class="control-quarter">
      <div class="control percent">%</div>
      <div class="control nine" onclick="addToInput(9);">9</div>
      <div class="control six" onclick="addToInput(6);">6</div>
      <div class="control three" onclick="addToInput(3);">3</div>
      <div class="control equals" onclick="equals();">=</div>
    </div>
    <div class="control-quarter">
      <div class="control divide" onclick="division();">÷</div>
      <div class="control times" onclick="multiplication();">x</div>
      <div class="control minus" onclick="subtraction();">-</div>
      <div class="control plus" onclick="addition();">+</div>
    </div>

  </div>

</div>
            
          
!
            
              * {
  box-sizing: border-box;
}

body {
  background-color: #001222;
  color: white;
  padding: 30px;
}

.noselect {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.calculator {
  border: 1px solid white;
  width: 440px;
  height: 440px;
  margin: 30px auto 0;
}

.screen {
  height: 80px;
  padding: 5px;
  border: 1px solid white;
  margin: 20px 20px 0;
  position: relative;
}

.screen-inner {
  position: absolute;
  bottom: 5px;
  font-size: 28px;
  font-family: monospace;
  width: 96.4%;
  text-align: right;
}

.controls {
  font-family: monospace;
  font-size: 2rem;
  padding: 20px;
  text-align: center;
}

.control-quarter {
  width: 20%;
  display: inline-block;
  vertical-align: top;
}

.control {
  width: 85px;
  height: 50px;
  line-height: 50px;
  text-align: center;
  border: 1px solid white;
  cursor: pointer;
  transition: 0.3s all;
  margin-bottom: 10px;
}

.control:hover {
  background-color: rgba(255, 255, 255, 0.06);
  transition: 0.3s all;
}

.plus {
  height: 110px;
  position: relative;
  line-height: 110px;
}

.percent {
  visibility: hidden;
}
            
          
!
            
              // Global Variables =============================+

var input = 0; // General input to be evaluated
var temp = ""; // Holds value to be evaluated

// Global Functions =============================+

// Update calculator
var updateCalculatorDisplay = function(n) {
  $('.output').text(n);
};

// Add to Input
var addToInput = function(n) {
  if (input == 0) {
    input = '' + n;
  } else {
    input += '' + n;
  }
  updateCalculatorDisplay(temp + input);
};

// Add decimal to Input
var addDecimalToInput = function() {
  if (input.indexOf(".") == -1) {
    input += '.';
    updateCalculatorDisplay(temp + input);
  }
};

// Division
var division = function() {
  temp += input + ' / ';
  input = 0;
  updateCalculatorDisplay(temp);
}

// Multiplication
var multiplication = function() {
  temp += input + ' * ';
  input = 0;
  updateCalculatorDisplay(temp);
}

// Subtraction
var subtraction = function() {
  temp += input + ' - ';
  input = 0;
  updateCalculatorDisplay(temp);
}

// Addition
var addition = function() {
  temp += input + ' + ';
  input = 0;
  updateCalculatorDisplay(temp);
}

// Equals
var equals = function() {
  temp += input;
  var result = math.eval(temp);
  updateCalculatorDisplay(temp + ' = ' + result);
  input = '';
  temp = '';
}

// Clear All
var clearAll = function() {
  input = 0;
  temp = '';
  updateCalculatorDisplay(input);
};

// Clear input
var clearInput = function() {
  input = 0;
  updateCalculatorDisplay(input);
}

// Document Ready ===============================+

$(document).ready(function() {

  // Initial output
  $('.output').text(input);

});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console