5

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/

1
  • how can they check a checkbox that isn't displayed? Commented Jan 3, 2014 at 17:42

1 Answer 1

13

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/

Sign up to request clarification or add additional context in comments.

7 Comments

what if to show label before the check-box? (in RTL)
Why would it matter since checkbox is hidden from view? Can't you make it render in LTR?
Funny, but I cannot show the image on right side of its label.
Ah, now I understand what you are talking about, my morning coffee just kicked in :) Did you try setting the background position and change the padding to be right instead of left. ...png') no-repeat right center;
Fiddle no longer works because of resources that are no longer available.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.