Home > Back-end >  Could the height of a grid item be modified individually to make it equal to the sum of two(or more)
Could the height of a grid item be modified individually to make it equal to the sum of two(or more)

Time:01-17

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 >
    <div id="screen">
      <div>
        <div id="funBtns">
          <div id="acBtn" ><button>AC</button></div>
          <div id="clearBtn" ><button>Clear</button></div>
          <div id="backBtn" ><button>Back</button></div>
          <div id="divide" ><button>/</button></div>
          <div id="one" ><button>1</button></div>
          <div id="two" ><button>2</button></div>
          <div id="three" ><button>3</button></div>
          <div id="multiply" ><button>*</button></div>
          <div id="four" ><button>4</button></div>
          <div id="five" ><button>5</button></div>
          <div id="six" ><button>6</button></div>
          <div id="subtract" ><button>-</button></div>
          <div id="seven" ><button>7</button></div>
          <div id="eight" ><button>8</button></div>
          <div id="nine" ><button>9</button></div>
          <div id="plus" ><button> </button></div>
          <div id="decimal" ><button>.</button></div>
          <div id="zero" ><button>0</button></div>
          <div id="equal" ><button>=</button></div>
        </div>
      </div>
</body>

</html>

CodePudding user response:

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 >
  <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 > </button>
    <button>.</button>
    <button>0</button>
    <button>=</button>
  </div>
</div>

  •  Tags:  
  • Related