radiobutton
element, as well as possible, is suitable for this task, you only need to customize it a little bit. This is where the problems begin. The fact is that the rendering of the radiobutton
and checkbutton
is not controlled by the browser, but by the OS. Accordingly, most CSS properties (for example, background-color
) do not affect them.radiobutton
, but they all seemed too complicated for me, so I decided to create my own.label
, the radiobutton
switches. So you can customize not the radiobutton
, but the label
. <input type="radio" name="color" value="#0000ff" id="blue"/> <label for="blue" class="blue"></label> <input type="radio" name="color" value="#00ffff" id="cyan"/> <label for="cyan" class="cyan"></label>
radiobutton
and signatures to them. // radiobutton input[type="radio"]{display: none;} // label label{ width: 20px; height: 20px; } label.blue{background-color: blue;} label.cyan{background-color: #00ffff;} // input[type="radio"]:checked+label{ border: black solid 2px; }
radiobutton
and draw the way we want the label
. Draw a label
for the marked state input[type="radio"]:checked+label
. Everything is simple and elegant.label
. As a result, my method does not work on the iPhone and iPad. The most interesting thing is that Safari on Windows chews everything correctly. Unfortunately, there was not a single iMac to check. var deviceAgent = navigator.userAgent.toLowerCase(); var iOS = deviceAgent.match(/(iphone|ipod|ipad)/); if (iOS) { $('label').click(function (event) { $('#' + $(event.target).attr('for')).attr('checked', true).change(); }); }
Source: https://habr.com/ru/post/150760/
All Articles