cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-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.

            
              <head>
	<link href='https://fonts.googleapis.com/css?family=Lato:400,100,700' rel='stylesheet' type='text/css'>
</head>
<body>
 <div id="calculatorBody">
  <div id="resultScreen"><span class="result"></span></div>
	<ul  id="buttonsBody">
      <li class="ac btn btn-grey prviRed">AC</li>
      <li class="sqrt btn btn-grey prviRed">√</li>
      <li class="kvadrat btn btn-grey prviRed">x</li>
      <li class="racOperacija btn btn-orange prviRed">/</li>
      <li class="num btn btn-number drugiRed">7</li>
      <li class="num btn btn-number drugiRed">8</li>
      <li class="num btn btn-number drugiRed">9</li>
      <li class="racOperacija btn btn-orange drugiRed">*</li>
      <li class="num btn btn-number treciRed">4</li>
      <li class="num btn btn-number treciRed">5</li>
      <li class="num btn btn-number treciRed">6</li>
      <li class="racOperacija btn btn-orange treciRed">-</li>
      <li class="num btn btn-number cetvrtiRed">1</li>
      <li class="num btn btn-number cetvrtiRed">2</li>
      <li class="num btn btn-number cetvrtiRed">3</li>
      <li class="racOperacija btn btn-orange cetvrtiRed">+</li>
      <li class="num nula btn btn-number btn-nula petiRed">0</li>
      <li class="tocka btn btn-number petiRed">.</li>
      <li class="jednako btn btn-orange petiRed">=</li>
	</ul>
</div>
  


</body>
            
          
!
            
              body {
	min-height: 100vh; 
  padding-top: 30vh;
	background: linear-gradient(10deg,#2bffff, #2acdff);
	font-family: 'Lato', Helvetica, Arial, sans-serif;
	font-size: 16px;
}
ul {
  list-style-position: inside;
	padding: 0;
	margin: 0;
	text-decoration: none;
}
#calculatorBody {
	position: relative;
	background-color: #fff;
	box-shadow: 0px 20px 35px rgba(0,0,0,.4);
	width: 400px;
	height: 600px;
	border-radius: 30px;
	margin: 60px auto;
}
#resultScreen {
	position: absolute;
	padding: 0;
	background-color: transparent;
	border-bottom: 2px solid #ddd;
	width: 90%;
	height: 20%;
	left: 5%;
	right: 5%;
	top: 5%;
	overflow: hidden;
}
#buttonsBody {
	position: absolute;
	border-radius: 5px;
	width: 90%;
  right: 5%;
	top: 35%;
  margin: 0 auto;
	text-align: center;
}
.btn {
    display: inline-block;
    cursor: pointer;
    width: 24%;
    height: 50px;
    background: transparent;
    color: #fff;    
    font-size: 2em;
    border-radius: 3px;
    border-bottom: 2px solid #ddd;
    padding-top: 12px;
    margin: 2px 0;
}
.btn-grey {
	background-color: #ddd;
	border-bottom: 2px solid #C5C5C5;
}
.btn-grey:hover {
	background-color: #C5C5C5;
}
.btn-orange {
	background-color: #2acdff;
	border-bottom: 2px solid #1c8daf;
}
.btn-orange:hover {
	background-color: #3789CC;
}
.btn-number {
	background-color: #F9F9F9;
	border-bottom: 2px solid #D6D6D6;
	color: #888;
}
.btn-number:hover{
	background-color: #D6D6D6;
}
.btn-nula {
	width: 48%;
}
.result {
	position: absolute;
	color: #888;
	right: 10px;
	bottom: 10px;
	font-size: 80px;
	font-weight: 100;
}
.kvadrat:after {
  content:"2";
  position: absolute;
  left: 235px;
  font-size: .6em;
  color: #fff;
}
.disabled {
  color: red;
}


@media screen and (max-width: 767px){
  #calculatorBody {
	width: 95%;
	height: 600px;
}  
  
}
            
          
!
            
              (function Calc(){

var screen = document.getElementById("resultScreen").querySelector(".result");
var list = document.getElementById("buttonsBody");
var sqroot = document.getElementsByClassName("sqrt");
var answer = "";

list.addEventListener("click", function(e){
  var target = e.target;
  var tarCont = target.textContent;
  var cls = target.classList;
  var rez = screen.textContent;
  var racOp = cls.contains("racOperacija").textContent;

    
  if (cls.contains("num") || cls.contains("racOperacija")){
    answer = "";
    answer += tarCont;
    screen.textContent += answer;
  } else if (cls.contains("ac")){
    answer = "";
    screen.textContent = answer;
  } else if (cls.contains("sqrt")){
    answer = Math.sqrt(rez);
    if (answer.toString().length > 6) {
      screen.textContent = answer.toFixed(3);
    } else{
      screen.textContent = answer;
    }
  } else if (cls.contains("kvadrat")){
    answer = rez*rez;
    if (answer.toString().length > 6 ){
    screen.textContent = answer.toFixed(2); 
    } else {
    screen.textContent = answer;
    }
  } else if (cls.contains("tocka")){
    answer = "";
    answer += tarCont;
    screen.textContent += answer;
  } else if (cls.contains("jednako")){
    try{ 
    answer = eval(screen.textContent);
    if(isNaN(answer)){
      alert("Invalid input");
    } else{
        if (answer.toString().length > 6) {
        screen.textContent = answer.toFixed(3);
      } else {
        screen.textContent = answer;
      }
    }
    }catch(e){
      screen.textContent = "Error";
  }}

});
}())







            
          
!
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