I have a form where I use several plus and minus buttons to add new elements to the form as needed by the user. I've used a custom button style. I've used this site to get the necessary css to make sure the text is centered. But this only seems to work in some instances of the button.
function unhide(id) {
var myForm = document.forms.mrform;
var myControls = myForm.elements[id.concat('[]')];
for (var i = 0; i < myControls.length; i++) {
var aControl = myControls[i];
if ($(aControl).is(':hidden')) {
$("#".concat(id.concat(i+1).replace(/ /g, "_"))).show();
break;
}
}
}
function hide(id) {
var myForm = document.forms.mrform;
var myControls = myForm.elements[id.concat('[]')];
for (var i = myControls.length; i > 0 ; i--) {
var aControl = myControls[i];
if ($(aControl).is(':visible')) {
$("#".concat(id.concat(i+1).replace(/ /g, "_"))).hide();
break;
}
}
}
.pmbutton {
background-color: greenyellow;
border: none;
color: black;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 10px;
height: 17px;
width: 17px;
padding: 0px;
margin: 0px 0px 0px 4px;
vertical-align: middle;
line-height: 17px;
box-sizing: border-box;
}
.hideme {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id='mrform' action='report_generator.php' method='post' autocomplete='off' onkeypress='return event.keyCode != 13;'>
<table class='subform'>
<tr id='Objective_Item1'><td class='prompt text'>Objective Item #1 :</td><td class='input'><input class='inputbox text' type='text' name='Objective Item[]'><button type='button' class='pmbutton' onclick='unhide("Objective Item")'>+</button><button type='button' class='pmbutton' onclick='hide("Objective Item")'>-</button></td></tr>
<tr id='Objective_Item2' class='hideme'><td class='prompt text'>Objective Item #2 :</td><td class='input'><input class='inputbox text' type='text' name='Objective Item[]'></td></tr>
<tr id='Objective_Item3' class='hideme'><td class='prompt text'>Objective Item #3 :</td><td class='input'><input class='inputbox text' type='text' name='Objective Item[]'></td></tr>
<tr id='Objective_Item4' class='hideme'><td class='prompt text'>Objective Item #4 :</td><td class='input'><input class='inputbox text' type='text' name='Objective Item[]'></td></tr>
<tr id='Objective_Item5' class='hideme'><td class='prompt text'>Objective Item #5 :</td><td class='input'><input class='inputbox text' type='text' name='Objective Item[]'></td></tr>
<tr id='Objective_Item6' class='hideme'><td class='prompt text'>Objective Item #6 :</td><td class='input'><input class='inputbox text' type='text' name='Objective Item[]'></td></tr>
<tr id='Objective_Item7' class='hideme'><td class='prompt text'>Objective Item #7 :</td><td class='input'><input class='inputbox text' type='text' name='Objective Item[]'></td></tr>
<tr id='Objective_Item8' class='hideme'><td class='prompt text'>Objective Item #8 :</td><td class='input'><input class='inputbox text' type='text' name='Objective Item[]'></td></tr>
<tr id='Objective_Item9' class='hideme'><td class='prompt text'>Objective Item #9 :</td><td class='input'><input class='inputbox text' type='text' name='Objective Item[]'></td></tr>
<tr id='Objective_Item10' class='hideme'><td class='prompt text'>Objective Item #10 :</td><td class='input'><input class='inputbox text' type='text' name='Objective Item[]'></td></tr>
</table>
</form>
The functionality is fine, but the text is not vertically centered in the button in some instances and IS in others. Seems to be a single pixel off in random buttons. I've viewed it in Firefox and Chrome (which seems to be worse). Any suggestions as to the cause?
Edit: Adding an image of several renderings of the same button on one page of the site. The only property I change between some of them is the background color. Both vertical and horizontal alignment vary, it seems.