Create a simple counter application project in javascript with using HTML & CSS..
HTML part:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="count-value">
<h1 id="result"></h1>
<button onclick="increase()">+</button>
<button onclick="decrease()">-</button>
<button onclick="reset()">Reset</button>
</div>
</body>
</html>
JS part:
<script>
let count = 0;
let element = document.getElementById("result");
element.innerText = count;
function increase() {
count = count + 1;
element.innerText = count;
}
function decrease() {
count = count - 1;
element.innerText = count;
}
function reset() {
count = 0;
element.innerText = count;
}
</script>
CSS style:
<style>
body {
/* border: 2px solid green; */
background: url(https://img.freepik.com/free-vector/gradient-numerology-background_23-2150051043.jpg?ga=GA1.1.1592619047.1747411105&semt=ais_items_boosted&w=740)repeat;
width: 100%;
height: 100vh;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
}
.count-value {
background-color: white;
border: 1px solid;
border-radius: 6px;
width: 300px;
height: 150px;
}
h1 {
/* border: 1px solid; */
padding: 0px 126px;
}
.count-value button {
/* border: 1px solid; */
border-radius: 6px;
width: 50px;
height: 30px;
background-color: black;
color: white;
padding: 5px 0px;
}
</style>
Output:
Top comments (0)