How can I make my modified tabbable switches?

I used some CSS to create mobile radio buttons, hiding inputand using elements instead label. The code is below, but I did jsFiddle for convenience .

My problem is that the main usability problem arises when using the keyboard to navigate the form: the fields are no longer tabulated. I tried to add attributes tabindexto hidden inputs, labelsand to div. The first two do not work at all, adding a tabindexdiv to the work (the div is highlighted), but I cannot interact with form elements at all (for example, using the arrow keys).

Is it possible to fix this only with CSS / HTML? I would prefer not to return to javascript, but if there is no other way, I think I will have to.

<input type='text'>
<div class='radio-select'>
  <input checked="checked" id="no" name="yes_no" value="False" type="radio">
  <label for="no">
    No
  </label>
  <input id="yes" name="yes_no" value="True" type="radio">
  <label for="yes" >
    Yes
  </label>
</div>
<input type='text'>
<style>
.radio-select label{
    background: #f00;
    border:1px solid #ddd;
    border-radius:10px;
    padding:10px;
    margin:5px 0;
    max-width:200px;
    clear:both;
    display: block;
    cursor:pointer;
}
.radio-select input[type='radio']{
    display: none;
}
.radio-select input[type='radio']:checked + label{
    background:#0f0 !important;
}
.radio-select input[type='radio']:checked + label:before{
    content:"✔";
}
</style>
+3
source share
1 answer

If you hide inputby setting their opacity to 0, they will still tabulate:

.radio-select input[type='radio']{
    opacity:0;
    filter:alpha(opacity=0);
    position:absolute
}

jsfiddle

+6
source

Source: https://habr.com/ru/post/1651295/


All Articles