Calculator Using HTML, CSS & JavaScript | Glass Morphism Effect || Coding Power

 


Hello everyone, you can learn how to create a Calculator Using HTML, CSS & JavaScript in this blog. So if you want to learn then follow all the steps carefully.  

Watch Full Tutorial on YouTube


Source Code Of Calculator in GlassMorphism

Step 1: Create Index.html File

Create one file with the name index.html and paste the below code in this file. 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Calculator in GlassMorphism - Coding Power</title>
</head>
<body>

   <div class="container">
       <div class="content">
           <input type="text" class="result" id="result" readonly>
           <span class="number clear" onclick="document.getElementById('result').value = ''">C</span>
           <span class="number" onclick="display('%')">%</span>
           <span class="number" onclick="display('/')">/</span>
           <span class="number" onclick="display('7')">7</span>
           <span class="number" onclick="display('8')">8</span>
           <span class="number" onclick="display('9')">9</span>
           <span class="number" onclick="display('*')">*</span>
           <span class="number" onclick="display('4')">4</span>
           <span class="number" onclick="display('5')">5</span>
           <span class="number" onclick="display('6')">6</span>
           <span class="number" onclick="display('-')">-</span>
           <span class="number" onclick="display('1')">1</span>
           <span class="number" onclick="display('2')">2</span>
           <span class="number" onclick="display('3')">3</span>
           <span class="number" onclick="display('+')">+</span>
           <span class="number" onclick="display('00')">00</span>
           <span class="number" onclick="display('0')">0</span>
           <span class="number" onclick="display('.')">.</span>
           <span class="number" onclick="result()">=</span>
       </div>
   </div>

   <script>

       function display(value){
           document.getElementById("result").value += value;
       }

       function result(){
           let displayvalue = document.getElementById("result").value;
           let result = eval(displayvalue);
           document.getElementById("result").value = result;
       }
   </script>

</body>
</html>


Step 2: Create style.css File

Create one file with the name style.css and paste the below code in this file.

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap');

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

body{
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgb(49, 45, 45);
}

.container{
    position: relative;
    grid-column: span 4;
}

.container::before{
    content: "";
    position: absolute;
    width: 250px;
    height: 250px;
    border-radius: 50%;
    left: -145px;
    top: -85px;
    background-color: #08AEEA;
    background-image: linear-gradient(0deg, #08AEEA 0%, #2AF598 100%);
    z-index: -1;
}

.container::after{
    content: "";
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    right: -100px;
    bottom: -80px;
    background-color: #4158D0;
    background-image: linear-gradient(43deg, #4158D0 0%, #C850C0 46%, #FFCC70 100%);
    z-index: -1;
}

.container .content{
    background: rgba(255, 255, 255, 0.1);
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    box-shadow: 3px 3px 30px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
}

.container .content .result{
    grid-column: span 4;
    outline: none;
    border: none;
    height: 80px;
    font-size: 20px;
    padding-right: 15px;
    text-align: right;
    background: transparent;
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.container .content .number{
    width: 70px;
    height: 70px;
    line-height: 70px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    text-align: center;
    color: white;
    font-size: 20px;
    transition: 0.2s;
}

.container .content .number:hover{
background: #d8e42e ;
color: black;
}

.container .content .clear{
    grid-column: span 2;
    width: 140px;
}


That's It. if you face any error/problem then comment below or Download this code file and then try again. This file is a Zip file so after download you have to extract it.

For Download Code You have to wait 30 seconds.


Post a Comment

Previous Post Next Post