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.

            
              <!--
Inspired by https://dribbble.com/shots/723449-Calc-GUI
-->
<div class="calculator">
  <div class="textbox"></div>
  <div class="row">
    <div class="btn ac accent">AC</div>
    <div class="btn ce accent"><</div>
    <div class="btn divide">/</div>
    <div class="btn multiply">×</div>
  </div>
  <div class="row">
    <div class="btn 7">7</div>
    <div class="btn 8">8</div>
    <div class="btn 9">9</div>
    <div class="btn minus">-</div>
  </div>
  <div class="row">
    <div class="btn 4">4</div>
    <div class="btn 5">5</div>
    <div class="btn 6">6</div>
    <div class="btn plus">+</div>
  </div>
  <div class="row">
    <div class="btn 1">1</div>
    <div class="btn 2">2</div>
    <div class="btn 3">3</div>
    <div class="btn equal tall">=</div>
  </div>
  <div class="row">
    <div class="btn 0 wide">0</div>
    <div class="btn dot">.</div>
  </div>
</div>
            
          
!
            
              /* Box Sizing Fix */
html {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
*, *:before, *:after {
  -webkit-box-sizing: inherit;
  -moz-box-sizing: inherit;
  box-sizing: inherit;
  }
/* ------ */

$background-color: #B0D0D7;
$main-color: #F7F4ED;
$main-color-dark: #C4BFB3;
$secondary-color: #8D8F9A;
$text-color: #71625B;
$accent-color: #DB7542;
$highlight-color: #889DD3;
$shadow-color: #468594;

body {
  background: $background-color;
}

html * {
  font-family: 'Quicksand';
}

.calculator {
  width: 340px;
  height: 390px;
  background: $main-color;
  border-radius: 7px;
  box-shadow: 5px 10px 25px $shadow-color,
              inset 0px 4px 2px white,
              inset 0px -2px 7px $main-color-dark;
  border: 3px solid $main-color-dark;
  color: $text-color;
  font-size: 40px;
  font-family: sans-serif;
  font-weight: 700;
  padding: 20px;
  
  position: absolute;
  margin: auto;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

.textbox {
  height: 70px;
  border: 2px solid #dcd9d2;
  box-shadow: 0px 4px 2px white;
  border-radius: 5px;
  background: linear-gradient(#e0d9ce, #f1ede6, #f7f4ef);
  line-height: 70px;
  text-align: right;
  padding: 0 10px;
  &::selection {
    background: $highlight-color;
    color: $main-color;
  }
}

.btn {
  display: inline-block;
  background: grey;
  width: 64px;
  height: 45px;
  margin-top: 10px;
  border: 2px solid #dfdcd7;
  box-shadow: inset 0px 3px 2px white,
    0px 1px 3px #d4d0ca;
  border-radius: 5px;
  background: $main-color;
  font-size: 20px;
  line-height: 45px;
  text-align: center;
  cursor: pointer;
  transition: all .1s ease;
  &:active{
    box-shadow: 0px 0px 3px #d4d0ca;
    background: darken($main-color, 3);
  }
  -webkit-user-select: none;  /* Chrome all / Safari all */
  -moz-user-select: none;     /* Firefox all */
  -ms-user-select: none;      /* IE 10+ */
  user-select: none;          /* Likely future */     
}

.btn.accent {
  border: 2px solid #b64811;
  box-shadow: inset 0px 4px 2px #f78e58,
    0px 1px 3px #d4d0ca;
  border-radius: 5px;
  color: $main-color;
  background: $accent-color;
  &:active{
    box-shadow: 0px 0px 3px #d4d0ca;
    background: darken($accent-color, 5);
  }
}

.btn.wide {
  width: 140px;
}

.btn.tall {
  height: 100px;
  margin: 10px 3px;
  float: right;
  line-height: 100px;
  font-size: 30px;
  background: $secondary-color;
  border: 2px solid darken($secondary-color, 10);
  box-shadow: inset 0px 4px 2px lighten($secondary-color, 10),
    0px 1px 3px #d4d0ca;
  color: $main-color;
  &:active{
    box-shadow: 0px 0px 3px #d4d0ca;
    background: darken($secondary-color, 5);
  }
}
            
          
!
            
              var entries = [];
var input = '';
var total = '';

$(".btn").click(function() {
  var val = $(this).text();

  //Add Number
  if (!isNaN(val) || val === '.') {
    input += val;
    $(".textbox").html(input.substring(0, 10));
  }

  //Backspace
  else if (val == "<") {
    input = input.substring(0, input.length - 1);
    $(".textbox").text(input);
  }

  //Clear All
  else if (val == "AC") {
    input = '';
    entries = [];
    total = 0;
    $(".textbox").text('')
  }

  //Operations
  else if (val == "+") {
    entries.push(input);
    entries.push("+");
    input = '';
  } else if (val == "-") {
    entries.push(input);
    entries.push("-");
    input = '';
  } else if (val == "/") {
    entries.push(input);
    entries.push("/");
    input = '';
  } else if (val == "×") {
    entries.push(input);
    entries.push("*");
    input = '';
  } else if (val == "=") {

    entries.push(input);
    var subtotal = Number(entries[0]);

    for (var i = 1; i < entries.length; i++) {
      var nextNumber = Number(entries[i + 1]);
      var operation = entries[i];

      if (operation === "+") {
        subtotal += nextNumber;
      } else if (operation === "-") {
        subtotal -= nextNumber;
      } else if (operation === "*") {
        subtotal *= nextNumber;
      } else if (operation === "/") {
        subtotal /= nextNumber;
      }

      i++;
    }

    // Swap the '-' symbol so text input handles it correctly
    if (subtotal < 0) {
      subtotal = Math.abs(subtotal) + '-';
    }

    total = String(subtotal).substring(0, 10);
    
    $(".textbox").html(total);
    entries = [];
    input = total;
  } else {
    entries.push(input);
    entries.push(val);
    input = '';
  }
})
            
          
!
999px
Loading ..................

Console