Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling an input type=number

Tags:

html

css

Is it possible to apply a style in the inner "up arrow" and "down arrow" of a <input type="number"> in CSS? I would like to change the background of the up arrow to blue and the down arrow to red. Any ideas?

styling inner arrows

like image 503
Savrige Avatar asked Sep 24 '14 19:09

Savrige


People also ask

How do you write an input type number?

The <input type="number"> defines a field for entering a number. Use the following attributes to specify restrictions: max - specifies the maximum value allowed. min - specifies the minimum value allowed.

How do you change the input type number on an arrow?

Just rotate the arrow keys and set the opacity to 0. (they are now in the right place, invisible but clickable) Then set an :after and :before element over these invisible buttons. These elements can then be styled as desired.

Can we use style in input tag?

A style attribute on an <input> tag assigns a unique style to the input control. Its value is CSS that defines the appearance of the input element.


1 Answers

UPDATE 17/03/2017

Original solution won't work anymore. The spinners are part of shadow dom. For now just to hide in chrome use:

input[type=number]::-webkit-inner-spin-button {    -webkit-appearance: none;  }
<input type="number" />

or to always show:

input[type=number]::-webkit-inner-spin-button {    opacity: 1;  }
<input type="number" />

You can try the following but keep in mind that works only for Chrome:

input[type=number]::-webkit-inner-spin-button {       -webkit-appearance: none;      cursor:pointer;      display:block;      width:8px;      color: #333;      text-align:center;      position:relative;  }    input[type=number]::-webkit-inner-spin-button:before,  input[type=number]::-webkit-inner-spin-button:after {      content: "^";      position:absolute;      right: 0;  }    input[type=number]::-webkit-inner-spin-button:before {      top:0px;  }    input[type=number]::-webkit-inner-spin-button:after {      bottom:0px;      -webkit-transform: rotate(180deg);  }
<input type="number" />
like image 50
Alex Char Avatar answered Sep 21 '22 04:09

Alex Char