How do i realign text if my input value going outside buttons width

137
January 17, 2018, at 03:38 AM

When i trying to execute number in button's innerText and overwrite the original value with some new bigger number using Javascript. The new number did not realign center within my button. Please see picture.

I tried to use object.style.textAlign = 'center'; but have no luck.

Please help.

Answer 1

The issue you're seeing is the padding on the button shifting the text once it reaches a certain length. If you plan on having text be that long within the button then you might want to consider using an absolute position for the text:

JSFiddle Example

And like @j08691 said, please post a Minimal, Complete, and Verifiable example next time for easier understanding :).

READ ALSO
IE keypress event not firing for Enter key

IE keypress event not firing for Enter key

I'm trying to create a UI that allows a user to hit Enter to progress past most screensThis works great in most browsers, but seems to fail in IE

165
Dynamically settings contents of iframe and resize

Dynamically settings contents of iframe and resize

If I have the following iframe

193
Navbar sticks to top before reaching scroll point and won't return until reload of page

Navbar sticks to top before reaching scroll point and won't return until reload of page

I'm trying to implement a sticky navbar to a webpage I'm making

119