Custom Checkbox

前端 未结 2 772
感动是毒
感动是毒 2020-12-06 03:05

Hello i am trying to create a custom checkbox for my website like the image link provided. What would be the best way to go around doing this? Many thanks.

相关标签:
2条回答
  • 2020-12-06 03:11

    jQuery is your best bet, this is a checkbox plugin for example, but there are hundreds of them so something else may suit you better. Just google 'jquery custom checkbox'.

    0 讨论(0)
  • 2020-12-06 03:28

    There is a CSS trick that actually works by hiding the checkbox (or radio), defining a label (which in all relevant browsers will turn the checkbox on/off) that will be the visual representation, and using the :checked and + selectors.

    This is just a simple example:

    .foscheck input { display: none; }
    .foscheck label { display: block; width: 20px; height: 20px; background: red; }
    .foscheck input:checked + label { background: blue; }
    <div class="foscheck">
      <input type="checkbox" id="fos1" />
      <label for="fos1"></label>
    </div>

    jsFiddle Demo

    Downsides: the :checked selector unfortunately does not work on IE, only from IE9. You can apply a Javascript fallback only for IE through conditional comments though.

    Note: For accessibility, you should have some text describing the checkbox in the label, I just wanted to illustrate the effect.

    0 讨论(0)
提交回复
热议问题