• Resolved timhuk

    (@timhuk)


    Hi, I’m trying to style the label of a checked/selected radio to show it has been selected.

    I’ve tried the following CSS:

    .assess4 input[type=”radio”]:checked + label {
    background-color:#bfb;
    }

    But this isn’t working. Any advice would be gratefully received.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Where can we see the website in question?

    Thread Starter timhuk

    (@timhuk)

    My main site is still changing, but here is my sandbox form:

    https://splinedesign.co.uk/wp/assessment/

    As you can see on “Step 2” the radio buttons show a different color on mouseover but I need them to also show a different style when checked.

    • This reply was modified 3 years, 1 month ago by timhuk.
    Plugin Author Takayuki Miyoshi

    (@takayukister)

    I’ve tried the following CSS:

    .assess4 input[type=”radio”]:checked + label {
    background-color:#bfb;
    }

    But this isn’t working.

    Because nothing on the page matches the selector.

    Thread Starter timhuk

    (@timhuk)

    Thanks for your prompt replies Takayuki-san,

    How would you suggest I change my CSS (or the form) to style the labels or checked radios?

    Thread Starter timhuk

    (@timhuk)

    I have created a 2nd sample page. Here I am showing some radio buttons created manually with HTML code and also some radio buttons created with CF7. All of the buttons are styled with the same CSS.

    You will see that the top set of button labels change their style when selected.

    How can I do the same with the CF7 radios and labels?

    https://splinedesign.co.uk/wp/test/

    Thread Starter timhuk

    (@timhuk)

    I figured out how to solve this issue by using the feature Selectable recipient with pipes to generate my labels.

    Originally I was using a standard <label></label> tag to create the labels for my radio buttons. However this separates the label from the radio so that CSS can’t see a link between a input[type="radio"]:checked and its label.

    By using the Selectable recipient with pipes technique I can now style a selected label as follows.

    
    CF7 Form:
    [radio question-01 "Label for option 1|1"]
    [radio question-01 "Label for option 2|2"]
    
    CSS:
    input[type=radio]:checked + .wpcf7-list-item-label {
        background-color: #bfb;
        border-color: #4c4;
    }
    

    Example here

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to style the label of a checked radio button’ is closed to new replies.