Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add padding-right to an input type="number" when aligning right?

I can't believe I haven't been able to find anything about this problem.

In my new project the future user will have a column with some input type="number", and as numeric fields (there is not a single textone) I want the numbers aligned to the right.

I found the numbers too close to the arrows so, logically, I added to them a padding-right.

To my surprise, It seems I can't separate a little the numbers from the arrows. padding-right moves the arrows along the numbers.

Basically only Opera do the padding the right way. but not the other main 3 browsers I have tested so far as you can see in the image below.

enter image description here

So. Is there any way to separate numbers from arrows so it works at least in Firefox and Chrome (as we recomend for our web app's these 2 browsers?)

a JSFIDDLE with a simple example

like image 210
Alvaro Menéndez Avatar asked Sep 10 '15 15:09

Alvaro Menéndez


People also ask

How do you add padding to a text box?

Right-click the selection rectangle of the shape or text box you want to change. On the shortcut menu, click Format <object type>, and then click the Text Box tab. Under Text Box Margins, adjust the measurements to increase or decrease the distance between the text and the outer border of the text box or a shape.

How do you properly align a form?

Use the CSS text-align Property to Center a Form in HTML The text-align property takes the values like left , right , center , justify , etc. We can set the value to center to center the form. For example, apply the text-align property to the form tag in the style attribute, and set the property to center .


2 Answers

Rather than using padding-right use the following CSS

input::-webkit-outer-spin-button,  input::-webkit-inner-spin-button { margin-left: 20px; }  

and for Firefox above solution won't work, so the best solution is just to hide it :

input[type=number] {     -moz-appearance:textfield; } 

or you can try to "play" with some jquery plugin.

like image 114
SpiRT Avatar answered Sep 22 '22 05:09

SpiRT


This is pretty annoying, in my case i solved the situation by passing the spinner to the left.

<input dir="rtl" type="number"/>
like image 44
Pedro Pam Avatar answered Sep 22 '22 05:09

Pedro Pam