javascript - CSS Grid resizing buttons within grid -


i'm going through freecodecamp , trying make electronic calculator, still on, trying sizing , layout correct.

i'm using css grid buttons having issue when i'm trying resize buttons.

i have javascript function creates <button> element each button displayed on calculator , assigns in corresponding css grid-area property match grid.

the layout , function work perfectly, problem comes when i'm trying resize "equals" button, located column 4 , rows 4 , 5.

the button takes 1 column, 2 rows of grid.

as change height property of buttons in css, particular button collapses 1 column , 1 row.

hopefully makes sense, if not, here codepen: https://codepen.io/rorschach1234/pen/gxbbgg

and html:

<head>  <link href="https://fonts.googleapis.com/css?family=orbitron" rel="stylesheet">    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  </head>  <body>   <div class="container">     <h2 class="top">electronic calculator</h2>     <div class="display">       <h2>display</h2>     </div>     <div class="buttons">     </div>     </div> </body> 

the css:

$calc-font: 'orbitron';  .container {   margin: 5% 33%;   background: grey; }  .top {    font-family: $calc-font;   text-align: center;   padding-top: 5px; }  .display {   margin: 3% 5%;   padding-bottom: 3%;   background: white;   text-align: right;   font-family: $calc-font; }  .buttons {   margin: 0 5%;   padding-bottom: 3%;   display: grid;   grid-template-columns: repeat(4, 1fr);   grid-template-rows: repeat(5, 1fr);   grid-template-areas:      "clearall cleard divide multiply"     "seven 8 9 minus"     "four 5 6 add"     "one 2 3 equals"     "zero 0 period equals";     }  button {   height: 25px; } 

and javascript:

var btnclasses = ["clearall", "cleard", "divide", "multiply", "seven", "eight", "nine", "minus", "four", "five", "six", "add", "one", "two", "three", "equals", "zero", "period"];  var buttons = ["ac", "ce", "&divide;", "&times;", 7, 8, 9, "&minus;", 4, 5, 6, "+", 1, 2, 3, "=", 0, "."];  /*function creates button , adds corresponding grid-area match grid-template-areas layout in css*/  function createbuttons() {   (var = 0; i<btnclasses.length; i++) {     $(".buttons").append("<button class=\"" + btnclasses[i] + "\">" + buttons[i] + "</button>");     $("." + btnclasses[i]).css("grid-area", btnclasses[i]);     $("." + btnclasses[i]).css("font-family", "orbiton");                             }; };  $(document).ready(function() {   createbuttons(); }); 

appreciate help, thanks!

the height of each row in keypad defined in grid container:

.buttons {     display: grid;     grid-template-rows: repeat(5, 1fr); } 

so there 5 explicitly defined rows. have same height, equal distribution of free space in container.

but when set height on grid item automatically gets align-self: start, overriding grid-area sizing you've defined.

from spec:

6.2. grid item sizing

if grid item has intrinsic ratio or intrinsic size in relevant dimension, grid item sized align-self: start.

if want buttons 25px tall, , grid-area work, @ container level:

.buttons {     display: grid;     grid-template-rows: repeat(5, 25px); } 

revised codepen


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -