Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use div as radio-button

Tags:

How can I use a div as radio button ?

I mean that :

  • you can select a div and then it is bordered blue
  • you can only select one of them
like image 577
Tom291 Avatar asked Oct 04 '15 15:10

Tom291


1 Answers

If you want a CSS Only solution, this is an excellent one :

.labl {      display : block;      width: 400px;  }  .labl > input{ /* HIDE RADIO */      visibility: hidden; /* Makes input not-clickable */      position: absolute; /* Remove input from document flow */  }  .labl > input + div{ /* DIV STYLES */      cursor:pointer;      border:2px solid transparent;  }  .labl > input:checked + div{ /* (RADIO CHECKED) DIV STYLES */      background-color: #ffd6bb;      border: 1px solid #ff6600;  }
<label class="labl">      <input type="radio" name="radioname" value="one_value" checked="checked"/>      <div>Small</div>  </label>  <label class="labl">      <input type="radio" name="radioname" value="another" />      <div>Small</div>  </label>

Inspired by this answer

like image 182
eliksir jouvence Avatar answered Oct 13 '22 02:10

eliksir jouvence