Skip Navigation

[Gelöst] Checkbox css :checked+ label not working

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
The user would like to syle the label of a checkbox when the checkbox is checked.

Solution:
The user is using multiple checkbox module, which generates checkbox inside label, styling it with CSS is difficult, but using a Javascript workaround, it is easier.
https://toolset.com/forums/topic/checkbox-css-checked-label-not-working/#post-1565735

This support ticket is created vor 4 Jahren, 7 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

Dieses Thema enthält 6 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von SteffenM1628 vor 4 Jahren, 7 Monaten.

Assistiert von: Jamal.

Author
Artikel
#1565383

Tell us what you are trying to do?

Hey there. I want to style the checkbox labels when the checkbox is checked.
So i tried this in css

input[type= "checkbox"]:checked+ label {
 background-color: #569cc3!important;
}

But this won‘t work.
Could you help style the labe of a checkbox when the box is checked?

Cheers

#1565483

Hello and thank you for contacting the Toolset support.

I'll need to see your page to better help with this, can you share a URL where I can see this? Please tell me which checkbox to check.
I need to know if it is a checkbox on a form or on a search filter. Please tell me which one?

But in the meantime, I suggest adding a special class to the checkbox and scope the styles by this class. Let's say that the class is "my-custom-checkbox", the code then will be:

.my-custom-checkbox input[type= "checkbox"]:checked+label {
  background-color: #569cc3!important;
}

Looking forward to your reply.

#1565535

Hey Jamal,

thanks for your fast reply.

Your solution didn´t worked out. It is a checkbox field in a form to select taxonomies.

Is there a way to share with you the link secretly?

Cheers

#1565687

I activated the private reply, your next reply will be private.

If you don't mind, please share credentials to your site so I can handle this quickly.
*** Please make a FULL BACKUP of your database and website before sharing credentials.***

#1565735

Thank you for the access information. I was able to make what you want with a custom Javascript code instead of CSS code.
CSS solution is too hard because the checkbox is rendered inside the label instead of being a sibling of it. Check this screenshot versteckter Link

So I added the following code to the form and it seems to work, you can check your form page on the frontend:

jQuery(function($){
    $(".wpt-form-set-checkboxes-artikel_taxo input[type='checkbox']").change(function(event){
      var checkbox = $(event.target);
      var status = checkbox.attr('checked');
      if (status) checkbox.parent().css('background-color', '#569cc3');
      else checkbox.parent().css('background-color', '');
    })
})

I hope this helps. Let me know if you have any questions.

#1565887

hey jamal,

thanks for your work. It works. But this is not really satisfying using javascript instead of a simple line of css code.
Toolset needs to improve with this stuff a lot.
Why is that so hard with Toolset working with css.
At this time i need to display those checkboxes inline.
None of the classes or id´s do work.

really frustating.
could you help me please?

cheers

#1565931

My issue is resolved now. Thank you!