ruby on rails - Changing checkbox icon with simple_form -


i'm new @ rails , web apps , appreciate if this. using simple_form , trying change checkbox icon image css(scss) seems not working. codes below.

<div class="col-md-6">    <%= f.input :is_something, as: :boolean, input_html: { class: 'custom-check-box' } %> </div> 

generated code

<div class="col-md-6">   <div class="input boolean optional test_is_somethiing"><input value="0" type="hidden" name="test[is_something]" /><label class="boolean optional checkbox" for="test_is_somethiing"><input class="boolean optional custom-check-box" type="checkbox" value="1" checked="checked" name="test[is_something]" id="test_is_somethiing" />label</label></div> </div> 

and scss is

.custom-check-box {    opacity: 0;    vertical-align: middle;    input[type=checkbox] + label:after {      opacity: 1;      display: inline-block;      background: image-url('check_box_off.png');      background-repeat: no-repeat;      vertical-align: middle;      background-size: 50%;      cursor: pointer;      &:checked + label:after {        opacity: 1;        display: inline-block;        background-size: 50%;        background: image-url('check_box_on.png');        background-repeat: no-repeat;        vertical-align: middle;        cursor: pointer;      }    }  } 

your missing few things working.

in html need have <label> tag for="" attr, so;

<div>   <input id="custom-checkbox" class="custom-check-box" type="checkbox" />   <label for="custom-checkbox"></label> </div> 

the labels attr needs match checkbox's id

then scss change input[type=checkbox] + label:after & + label:after, so;

.custom-check-box {    display: none;    vertical-align: middle;     & + label:after {      content: '';      padding: 16px;      display: inline-block;      background: image-url('check_box_off.png');      background-repeat: no-repeat;      vertical-align: middle;      background-size: 50%;      cursor: pointer;     }     &:checked + label:after {      background: image-url('check_box_on.png');    }   } 

your :after pseudos require content attr them work.

i created codepen you


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -