I am trying to make a calculator in CSS using a CSS grid. I want one of the buttons which is plus to occupy the height of two rows. However, when I use the height property the button shift from its place rather than bringing a change to its height.How can make the button the height of two rows? Here is the code:
.claculator {
display: grid;
margin: 0 auto;
border: 2px solid black;
width: 350px;
height: 400px;
border-radius: 5px;
}
#screen {
height: 70px;
background-color: #e3dede;
margin: 12px 9px;
border-radius: 5px;
}
#funBtns {
display: grid;
grid-template-columns: repeat(4, 1fr);
margin-top: 115px;
row-gap: 20px;
grid-template-rows: repeat(5, 1fr);
}
.button {
align-self: end;
justify-self: center;
}
button {
width: 50px;
height: 30px;
background-color: #191a1c;
color: white;
border: none;
border-radius: 5px;
}
button:hover {
transform: translateY(-5px);
transition: 200ms ease-out;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="claculator">
<div id="screen">
<div>
<div id="funBtns">
<div id="acBtn" class="button"><button>AC</button></div>
<div id="clearBtn" class="button"><button>Clear</button></div>
<div id="backBtn" class="button"><button>Back</button></div>
<div id="divide" class="button"><button>/</button></div>
<div id="one" class="button"><button>1</button></div>
<div id="two" class="button"><button>2</button></div>
<div id="three" class="button"><button>3</button></div>
<div id="multiply" class="button"><button>*</button></div>
<div id="four" class="button"><button>4</button></div>
<div id="five" class="button"><button>5</button></div>
<div id="six" class="button"><button>6</button></div>
<div id="subtract" class="button"><button>-</button></div>
<div id="seven" class="button"><button>7</button></div>
<div id="eight" class="button"><button>8</button></div>
<div id="nine" class="button"><button>9</button></div>
<div id="plus" class="button"><button>+</button></div>
<div id="decimal" class="button"><button>.</button></div>
<div id="zero" class="button"><button>0</button></div>
<div id="equal" class="button"><button>=</button></div>
</div>
</div>
</body>
</html>
>Solution :
However, when I use the height property the button shift from its place rather than bringing a change to its height
The buttons are not direct children of the grid. You could simplify things by removing the containing divs:
.claculator {
display: grid;
grid-template-rows: 70px 1fr;
grid-gap: 35px 0;
margin: 0 auto;
border: 2px solid black;
width: 350px;
height: 400px;
border-radius: 5px;
padding: 12px 9px;
}
#screen {
background-color: #e3dede;
border-radius: 5px;
}
#funBtns {
display: grid;
grid-template-columns: repeat(4, 50px);
grid-template-rows: repeat(5, 30px);
grid-gap: 20px 40px;
justify-content: center;
}
button {
background-color: #191a1c;
color: white;
border: none;
border-radius: 5px;
width: 100%;
}
button:hover {
transform: translateY(-5px);
transition: 200ms ease-out;
}
.button-plus {
grid-row: span 2;
}
<div class="claculator">
<div id="screen">
</div>
<div id="funBtns">
<button>AC</button>
<button>Clear</button>
<button>Back</button>
<button>/</button>
<button>1</button>
<button>2</button>
<button>3</button>
<button>*</button>
<button>4</button>
<button>5</button>
<button>6</button>
<button>-</button>
<button>7</button>
<button>8</button>
<button>9</button>
<button class="button-plus">+</button>
<button>.</button>
<button>0</button>
<button>=</button>
</div>
</div>