Like I've written in the title when you click one of the keys the others in the same column move too. How can I solve this problem? I would like them to stay in their place when you click one key! There should be the "button clicked effect" while respecting the spaces. I hope that the code is clear enough: I divided the calculator in two parts, the screen and the keyboard. You can find my problem in the keyboard section!
Thank you!
EDIT I've just edited the code with the solution that I was looking for! Check the edit for the details!
const keys = document.querySelectorAll('#keys-container div');
keys.forEach(key => key.addEventListener('mousedown', () => key.classList.add('press-div')
));
keys.forEach(key => key.addEventListener('mouseup', () => key.classList.remove('press-div')
));
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
body > div {
border: 1px solid black;
}
#display-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 142px;
width: 440px;
}
#display-border {
border: 1px solid black;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 80px;
width: 410px;
}
#display {
border: 1px solid black;
height: 70px;
width: 400px;
}
#keyboard {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 420px;
width: 440px;
}
#keys-container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-items: center;
justify-content: center;
border: 1px solid black;
gap: 12px;
height: 377px;
width: 410px;
}
#keys-container div {
display: flex;
justify-content: center;
align-items: center;
/*box-sizing: border-box;*/
border: 1px solid black;
border-bottom: 3px solid black;
height: 60px;
width: 80px;
transition: 0.01s;
}
#keys-container .press-div {
border-bottom: 1px solid black;
margin-top: 2px;
}
<body>
<div id="display-container">
<div id="display-border">
<div id="display"></div>
</div>
</div>
<div id="keyboard">
<div id="keys-container">
<div>ON/C</div>
<div>7</div>
<div>4</div>
<div>1</div>
<div>0</div>
<div>CE</div>
<div>8</div>
<div>5</div>
<div>2</div>
<div>⋅</div>
<div>±</div>
<div>9</div>
<div>6</div>
<div>3</div>
<div>=</div>
<div>÷</div>
<div>×</div>
<div>−</div>
<div style="height: 136px">+</div>
</div>
</div>
</body>