Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent buttons moving position when value changes

I have 4 buttons in a 2 x 2 grid. The buttons change text when I click on them.

The problem is that when they change from a blank value to a value, the buttons move. I can't seem to find a way to prevent this from happening.

CSS:

.A, .B {
height: 40px;
width: 40px;
padding: 0;
margin-top: -10px;
}

Javascript:

$('.A').click(function (evt) {
    var t = $(this)[0].innerHTML;
    if (t == '') $(this).text('A');
    else if (t == 'A') $(this).text('a');
    else if (t == 'a') $(this).text('');
    evt.preventDefault();
});
$('.B').click(function (evt) {
    var t = $(this)[0].innerHTML;
    if (t == '') $(this).text('B');
    else if (t == 'B') $(this).text('b');
    else if (t == 'b') $(this).text('');
    evt.preventDefault();
});

I have provided a jsfiddle here:

http://jsfiddle.net/2j9k0hLp/1/

like image 684
Family Avatar asked Sep 11 '14 17:09

Family


People also ask

How do you stop a moving button?

Right mouse over the button, select Format Autoshape and on the Properties tab select Don't move or size with cells.

How do you fix button positions?

You can use the position:absolute css property to position any element relative to a position:relative parent, which would be a wrapper around the h4 and button elements you have described. That way, the h4's visibility will not affect the position of the buttons.


1 Answers

It's due to weirdness with text/line alignments.

Try adding a vertical-align for example:

    vertical-align: top;
like image 61
willoller Avatar answered Nov 03 '22 20:11

willoller