Is it possible to use min, max and step in CSS?

3

I have an input of type number with min and max in HTML. is it possible to use this min , max and step in CSS?

<input class=input_number id=delai type=number min=1 max=10 step=2 name=delai required />

In CSS, something like this:

#delai{ min:1;max:10;step:2}
    
asked by anonymous 10.07.2015 / 15:10

2 answers

3

As already mentioned, CSS is not meant to define values but rather to define formatting, the visual aspect of the element.

You can, however, use JavaScript for this purpose.

Example with jQuery

$(document).ready(function() {
  $("#delay").attr({
    "min": 2,
    "max": 10,
    "step": 2
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script><inputid="delay" type="number" min="0" max="100" step="5" />

Example with JavaScript

document.addEventListener('DOMContentLoaded', function() {

  var meuCampo = document.getElementById("delay");

  meuCampo.min = 2;
  meuCampo.max = 10;
  meuCampo.step = 2;

}, false);
<input id="delay" type="number" min="0" max="100" step="5" />

Note: If the idea is to define certain CSS formatting based on the attribute value, you can see the solution in the @ Iago Correia Guimarães .

    
10.07.2015 / 20:57
0

You can not change the attribute value of an element with css, but you can set the style of a given element by its value using the html date attribute. Example:

<input id="delai" type="number" data-min="1" />

and in css:

#delai[data-min='1']{ seu estilo aqui }
    
10.07.2015 / 15:51