Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

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.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header>
  <h5>A Windows 7 Calculator look & logic mimic. Colored by <a href="https://codepen.io/pawsDesigns/pen/LBKnA">Nikolayrr</a>
  </h5>
</header>

<main>
  <div class="menu"><span>V</span>iew&nbsp;&nbsp; <span>E</span>dit&nbsp;&nbsp; <span>H</span>elp</div>
  <div class="display">
    <div class="outer-div">
      <div class="inner-div sm-text"></div>
    </div>
    <div class="outer-div">
      <div class="inner-div lg-text">0</div>
    </div>
    <div class="error"></div>
    <div class="m-icon">M</div>
  </div>
  <div class="keyboard">
    <button value="mc">MC</button>
    <button value="mr">MR</button>
    <button value="ms">MS</button>
    <button value="mPlus">M+</button>
    <button value="mMinus">M-</button>

    <button value="backspace">&#9664;--</button>
    <button value="ce">CE</button>
    <button value="c">C</button>
    <button value="sign">+-</button>
    <button value="sqrt">&radic;</button>

    <button class="btn-white" value="7">7</button>
    <button class="btn-white" value="8">8</button>
    <button class="btn-white" value="9">9</button>
    <button value="/">/</button>
    <button value="%">%</button>

    <button class="btn-white" value="4">4</button>
    <button class="btn-white" value="5">5</button>
    <button class="btn-white" value="6">6</button>
    <button value="*">*</button>
    <button value="reciprocal">1/x</button>
  </div>
  <div class="keyboard-bot">
    <div class="bot-left">
      <button class="btn-white" value="1">1</button>
      <button class="btn-white" value="2">2</button>
      <button class="btn-white" value="3">3</button>
      <button value="-">-</button>

      <button class="btn-wide btn-white" value="0">0</button>
      <button class="btn-white" value=".">.</button>
      <button value="+">+</button>
    </div>
    <div class="bot-right">
      <button class="btn-tall" value="=">=</button>
    </div>
  </div>
</main>
              
            
!

CSS

              
                body {
    font-size: 12px;
    font-family: 'Lato', sans-serif;
    background-color: #fbfbfb;

    background: url('https://www.hdwallpapers.in/walls/windows_7_original-wide.jpg') no-repeat center center fixed;
    background-size: cover;
}

header {
    position: absolute;
    top: 0;
    left: 0;
    padding: 0 0.6em;

    background-color: rgba(0,0,0,0.30);
    border-bottom-right-radius: 10px;
}
header h5 {
    color: white;
    font-family: sans-serif;
    font-size: 1.2em;
    margin: 1em;
}
header a {
    color: white;
}

main {
    width: 226px;
    margin: 8% 20%;
    padding-bottom: 12px;
    background-color: #d9e4f1;
    border: solid 1px gray;
}

.menu {
    border-bottom: solid 1px gray;
    font-size: 16px;
    padding: 2px 4px;

    background: linear-gradient(#f3f6fa 0%, #f3f6fa 34%, #D7E2EF 38%, #D7E2EF 100%);
}
.menu span {
    text-decoration: underline;
}

.display {
    position: relative;
    width: 86%;
    margin: 15px 0 3px 14px;
    border: solid 1px gray;
    border-radius: 3px;

    background: linear-gradient(#e5effb 0%, #E2EAF3 60%, #f5f8fd 80%, white 100%);
    box-shadow: 0px -1px 14px white inset;
}

.display div {
    color: black;
    text-align: right;
}

.outer-div {
    width:92%;
    margin-left:auto;
    margin-right:auto;
    text-align:right;
    overflow:hidden;
    white-space: nowrap;
  }
.inner-div {
    float:right;
}

.sm-text {
    font-size: 11px;
    letter-spacing: 2px;
    min-height: 16px;
    padding-top: 3px;
    margin: 0;
}
.lg-text {
    font-size: 20px;
    padding-left: 10px;
    margin: 0;
}
.m-icon {
    position: absolute;
    left: 4px;
    bottom: 8px;
    display: none;
}
.error {
    min-height: 12px;
    font-size: 10px;
    line-height: 8px;
    padding-right: 8px;
}

.keyboard {
    width: 100%;
    margin: 0 0 0 14px;
}
.keyboard-bot {
    margin-left: 3px;
}

button {
    width: 37px;
    height: 29px;
    margin: 2px 0;
    border: 1px solid rgba(0,0,0,.4);
    border-radius: 2px;
    
    background: linear-gradient(#F0F6FB 0%, #E2EAF3 49%, #D5E0ED 50%, #D7E2EF 100%);
    box-shadow: 0px -1px 6px white inset;
}
button:hover {
	background: linear-gradient(#FFE3B5 50%, #FCBF5D 50%);
	box-shadow: 1px 1px 2px #ffb76b,0px -1px 5px white inset;
	border-color: #FCBF5D;
}
.btn-white {
    font-size: 14px;
    background: linear-gradient(#f2f5f9 0%, #f2f5f9 49%, #eef2f7 50%, #eef2f7 100%);
    box-shadow: 1.6px 1.6px 0px white inset, -1.6px -1.6px 0px white inset;
}

.btn-wide {
    width: 77px;
}
.btn-tall {
    position: absolute;
    left: -1px;
    height: 63px;
}

.bot-left {
    display: inline-block;
    width: 70%;
    margin-left: 11px;
}
.bot-right {
    position: relative;
    display: inline-block;
    vertical-align: top;
    width: 20%;
}
              
            
!

JS

              
                /**
 *  I'm guessing Win Cal is doing a queue that stores each numbers group and operator as single entity.
 *  Here, it's char-by-char string manipulation + eval().
 */
$(function () {
    var numKeyReset = false;
    var lgQueue = "0";
    var smQueue = "";
    var query = "";
    var memory = "";

    var numRegEx = /^[0-9|.]$/;
    var operRegEx = /[+|\-|*|/|%]/;

    $('button').on('click', function () {
        var key = $(this).attr("value");

        /**
         *  Numbers
         */
        if (numRegEx.test(key)) {
            if (numKeyReset) {  // so previous result won't stack with new num
                clear();
                numKeyReset = false;
            }
            // TODO: zero handling at first digit is still different than win cal
            if (lgQueue[0] === "0" && lgQueue.length == 1) {
                if (query.length != 0) {
                    lgQueue = key;
                    query += key;
                } else {
                    lgQueue = key;
                    query = key;
                }
                sync();
            } else {
                lgQueue += key;
                query += key;
                sync();
            }
        }
        numKeyReset = false;

        /**
         *  Usual Operators
         */
        if (operRegEx.test(key)) {
            // for repeated operator keys
            if (operRegEx.test(query[query.length - 1])) {
                smQueue = smQueue.slice(0, -1) + key;
                query = query.slice(0, -1) + key;
                lgQueue = $('.lg-text').html();   // get gone value(lgQueue = "" below) from DOM
            } else {
                smQueue += lgQueue;
                // eager calulation to avoid operator precedence intentionally.
                if (operRegEx.test(query)) { 
                    query = lgQueue = evalStr(smQueue);
                }
                smQueue += key;
                query += key;
            }
            sync();
            lgQueue = "";   // so previous result won't stack with new num
        }
        if (key === '=') {
            smQueue = ""; 
            lgQueue = evalStr(query);
            query = lgQueue;
            sync();
            numKeyReset = true;
        }

        /**
         *  Speical keys
         */
        if (key === 'backspace') {
            if (lgQueue.length > 1) {
                lgQueue = lgQueue.slice(0, -1);
                
            } else if (lgQueue.length == 1) {
                lgQueue = "0";
            }
            query = query.slice(0, -1);
            sync();
        }
        if (key === 'sign') {
            if (lgQueue.length != 0) {
                if (lgQueue[0] != '-') {
                    var temp = query.slice(0, -lgQueue.length);
                    lgQueue = '-' + lgQueue;
                    query = temp + lgQueue;
                } else {
                    var temp = query.slice(0, -lgQueue.length);
                    lgQueue = lgQueue.substring(1, lgQueue.length);
                    query = temp + lgQueue;
                }
                sync();
            }
        }
        if (key === 'reciprocal') {
            var temp = query.slice(0, -lgQueue.length);
            lgQueue = evalStr("1/" + lgQueue);
            query = temp + lgQueue;
            sync();
        }
        if (key === 'sqrt') {
            var temp = query.slice(0, -lgQueue.length);
            lgQueue = evalStr(Math.sqrt(lgQueue));
            query = temp + lgQueue;
            sync();
        }

        /**
         *  Memory keys
         */
        if (key === 'ms') {
            memory = lgQueue;
            numKeyReset = true;
            $('.m-icon').show();
        }
        if (key === 'mc') {
            memory = "";
            $('.m-icon').hide();
        }
        if (key === 'mr') {
            var temp = query.slice(0, -lgQueue.length);
            lgQueue = memory;
            query = temp + memory;
            sync();
            numKeyReset = true;
        }
        if (key === 'mPlus') {
            if (memory.length == 0) {
                memory = lgQueue;
                $('.m-icon').show();
            } else {
                memory = evalStr(memory + "+" + lgQueue);
            }
            numKeyReset = true;
        }
        if (key === 'mMinus') {
            if (memory.length == 0) {
                memory = "-" + lgQueue;
                $('.m-icon').show();
            } else {
                memory = evalStr(memory + "-" + lgQueue);
            }
            numKeyReset = true;
        }
        if (memory == '0') {
            memory = "";
            $('.m-icon').hide();
        }

        /**
         *  Clears
         */
        if (key === 'c') {
            clear();
            sync();
        }
        if (key === 'ce') {
            query = query.slice(0, -lgQueue.length);
            lgQueue = "0";
            sync();
        }

        console.log(query);
    });

    function evalStr(str) {
        str = str + "";
        // fix parser errors
        str = str.replace(/^\-/,'0-');
        str = str.replace(/\-\-/,'+');

        var result = eval(str) + "";

        // error handlings
        if (result.indexOf('Infinity') != -1) {
            $('.error').html('Cannot divide by zero');
            return "0";
        }
        if (result.indexOf('NaN') != -1) {
            $('.error').html('Invalid input');
            return "0";
        }

        if (result.length > 12) {   // limited 12 digits output
            result = Number(result).toFixed(12);
        }
        return result;
    }

    function clear() {
        lgQueue = "0";
        smQueue = "";
        query = "";
        $('.error').html("");
    }
    function sync() {
        $('.lg-text').html(lgQueue);
        $('.sm-text').html(smQueue);
    }
});
              
            
!
999px

Console