I'm trying to make a JavaScript piano, with the keys being at the bottom of the screen, but setting bottom: 0px;
doesn't work
html {
height: 100%;
width: 100%;
position: relative;
}
/*keyboard div*/
#keyboard {
position: relative;
display: table;
width: 1366px;
height: 90px;
bottom: 0px;
}
/*keys, if those are important*/
#wk,
#bk {
display: table-cell;
border-color: #000000;
border-width: 1px;
border-style: solid;
}
#wk {
position: relative;
height: 90px;
width: 1.92%;
background-color: #ffffff;
}
#bk {
z-index: 1;
position: absolute;
height: 52px;
width: 58.05%;
right: -9.04px;
background-color: #000000;
}
<html>
<div id="keyboard">
<div id='wk'>
<div id='bk'></div>
</div>
<div id='wk' class=''>
</div>
</div>
CodePudding user response:
Replace your styles as given below:
#keyboard {
height: 90px;
position: fixed;
bottom: 0;
width: 100%;
background-color:#0000FF;
}
/*keys, if those are important*/
#wk, #bk {
border-color:#000000;
border-width: 1px;
border-style: solid;
}
#wk {
height:90px;
width: 1.92%;
background-color: #ffffff;
}
#bk {
height:52px;
width: 58.05%;
right: -9.04px;
background-color: #000000;
}
CodePudding user response:
Dont set bottom since that will move it from down to up rather set: top: 50%;
but since your width and height are odd use 41% to place it nicely
also its a nice practice to use em/rem or simply % and not px