Patrick Guinness
Patrick Guinness

Reputation: 397

css - replacing checkbox image

Hi I know this has been answered but I can't get it to work for me.

I have as HTML

<input type="hidden" name="data[Child][remember_me]" id="am_2_" value="0"/>
<input type="checkbox" name="data[Child][remember_me]"  class="checkboxLabel main_street_input" id="am_2" value="1"/>
<label for="am_2">&nbsp; &nbsp;&nbsp;</label> 

and then

.amPmCheckbox input[type="checkbox"]{
display: none;}     

.amPmCheckbox input[type="checkbox"]+label{
background: url('http://renegadeox.com/img/off.png') no-repeat; width:16px; height:17px;}

.amPmCheckbox input[type="checkbox"]:checked + label {
background: url('http://renegadeox.com/img/on.png');width:16px; height:17px;}

But it's not picking up the checked image. I can't figure out what's the problem, anyone any ideas? heres a fiddle btw

http://jsfiddle.net/ksCk8/

Upvotes: 5

Views: 30334

Answers (1)

epascarello
epascarello

Reputation: 207511

It picks up the checked image when the checkbox is checked. Issue you have is the fact nothing is clickable to make the checkbox checked.

Move the AM/PM into the label and use padding to shove it over instead of the spaces.

HTML:

<div class="amPmCheckbox">
    <input type="checkbox" name="data[Child][remember_me]" class="checkboxLabel main_street_input" id="am_2" value="1" />
    <label for="am_2">AM</label>
</div>

CSS:

.amPmCheckbox input[type="checkbox"] {
    display: none;
}
.amPmCheckbox input[type="checkbox"]+label {    
    background: url('http://renegadeox.com/img/off.png') no-repeat;
    height:17px;
    padding-left: 18px;
}
.amPmCheckbox input[type="checkbox"]:checked + label {
    background: url('http://renegadeox.com/img/on.png')  no-repeat;
    height:17px;
}

http://jsfiddle.net/JkDhN/1/

Upvotes: 13

Related Questions