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 id="calcCont">
  <div id="screen">0</div>
  <div id="numberCont">
    <button class="number">7</button>
    <button class="number">8</button>
    <button class="number">9</button>
    <button id="percent" class="operator">%</button>
    <button id="root" class="operator">&radic;</button>
    <button class="number">4</button>
    <button class="number">5</button>
    <button class="number">6</button>
    <button id="times" class="operator">&times;</button>
    <button id="divide" class="operator">&divide;</button>
    <button class="number">1</button>
    <button class="number">2</button>
    <button class="number">3</button>
    <button id="plus" class="operator">+</button>
    <button id="minus" class="operator">-</button>
    <button class="number">0</button>
    <button class="number">.</button>
    <button class="number">&plusmn;</button>
    <button id="clear">c</button>
    <button id="equal">=</button>
  </div>
</div>

            
          
!
            
              body {
  background-color: #700;
}

@font-face
{
  font-family: digital;
  src: url(http://fontsforweb.com/public/fonts/1091/DSDIGI.ttf);
}
#calcCont{
  position: relative;
  top: 0;
  left: 0;
  margin: 20% auto;
  width: 400px;
  height: 400px;
  border-radius: 10px;
  border: 1px solid #333;
  box-shadow: 3px 7px 1px #666;
  background-color: #DDD;
}
#screen{
  font-family: digital;
  font-size: 80px;
  width: 320px;
  height: 80px;
  margin: 15px auto;
  padding: 0 10px;
  background-color: #AAA;
  text-align: right;
  overflow: hidden;
  border: 2px inset #666;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  -moz-box-shadow: inset 0 0 10px #000000;
  -webkit-box-shadow: inset 0 0 6px #000000;
  box-shadow: inset 0 0 6px #000000;
  -ms-box-shadow: 1px 4px 0px #CCC;
}
#screen:after{
  content: '88888888';
  position: absolute;
  right: 41px;
  top: 15px;
  opacity: .2;
}
#numberCont{
  margin: 0 auto;
  width: 355px;
}
button{
  position: relative;
  top: 0;
  left: 0;
  margin: 10px;
  color: #fff;
  font-size: 30px;
  width: 47px;
  height: 47px;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  -webkit-transition: all .2s ease;
  -moz-transition: all .2s ease;
  -o-transition: all .2s ease;
  -ms-transition: all .2s ease;
  transition: all .2s ease;
}
button.number{
  background: #df4242;
  -webkit-box-shadow: 1px 4px 0px #a01b1b;
  -moz-box-shadow: 1px 4px 0px #a01b1b;
  -ms-box-shadow: 1px 4px 0px #a01b1b;
  box-shadow: 1px 4px 0px #a01b1b;
  border: 1px solid #a01b1b;
}
button.operator{
  background: #FF9933;
  -webkit-box-shadow: 1px 4px 0px #E69316;
  -moz-box-shadow: 1px 4px 0px #a01b1b;
  -ms-box-shadow: 1px 4px 0px #a01b1b;
  box-shadow: 1px 4px 0px #E69316;
  border: 1px solid #E68A2E;
}
#equal{
  background: #2EB82E;
  -webkit-box-shadow: 1px 4px 0px #009900;
  -moz-box-shadow: 1px 4px 0px #009900;
  -ms-box-shadow: 1px 4px 0px #009900;
  box-shadow: 1px 4px 0px #009900;
  border: 1px solid #006600;
}
#clear{
  background: #3E89D4;
  -webkit-box-shadow: 1px 4px 0px #326EAA;
  -moz-box-shadow: 1px 4px 0px #326EAA;
  -ms-box-shadow: 1px 4px 0px #326EAA;
  box-shadow: 1px 4px 0px #326EAA;
  border: 1px solid #2D6399;
}
button:active{
  top: 5px;
  left: 1px;
  outline: none;
  box-shadow: none !IMPORTANT;
  -webkit-box-shadow: none !important;
  -moz-box-shadow: none !important;
  -ms-box-shadow: none !important;
}

button:focus {
  outline:0;
}
            
          
!
            
              /**
 * NOTE: The JS code is not done yet and is currently meant as an 
 * example for simplistic use
 */
$(document).ready(function(){
  var ALLOWED_PLACES = 7; //how many numbers to allow on screen
  var firstPress = true; //is it the first button pressed
  var $screen = $('#screen'); //cache the screen
  var numCount = 0; //how many numbers on screen?
  var storeResult = null; // firstresult
  var operator = null; //operator previously pressed
  
  function handleNumber(object){
    if(firstPress){
      $screen.text('');
      firstPress = false;
    }
    if(ALLOWED_PLACES > numCount){
      $screen.text($screen.text() + object.text());
      numCount++;
    }
  }
  
  function handleOperator(type){
    if(storeResult === null){
      storeResult = parseInt($screen.text());
      operator = type;
      $screen.text('');
    }
    else{
      var thisResult = parseInt($screen.text());
      switch(operator){
        case 'plus':
          $screen.text(storeResult + thisResult);
          break;
        case 'minus':
          $screen.text(storeResult - thisResult);
          break;
        case 'times':
          $screen.text(storeResult * thisResult);
          break;
        case 'divide':
          $screen.text(storeResult / thisResult);
          break;
      }
      operator = type;
    }
  }
  
  $('button').click(function(){
    if($(this).attr('id') === 'clear'){
      $screen.text('0');
      firstPress = true;
      storeResult = null;
      operator = null;
      numCount = 0;
    }
    else if($(this).hasClass('number'))
      handleNumber($(this));
    else if($(this).hasClass('operator'))
      handleOperator($(this).attr('id'));
  });
  
});
            
          
!
999px
Loading ..................

Console