How to style a selected radio button AND include space as clickable?

bcsteeve

So I was reading CSS - How to Style a Selected Radio Buttons Label? here on SO and also this Q/A over on UX

I tried implementing both concepts and I can't seem to figure out how to do it, since a parent selector doesn't seem to exist. I'm sure one of you genii can help me.

Here's specifically the code I'm working with, but generic examples are fine:

<label for="ship-sfc-CNQM" class="checkboxLabel back">
    <div class="shippingcontainer">
        <input type="radio" name="shipping" value="sfc_CNQM" checked="checked" id="ship-sfc-CNQM">
        <div class="back sfc_logos" id="CNQM" title="China Post"></div><div class="back sfcdaterange"><span class="sfcdateprefixlong">Estimated delivery between </span><span class="sfcdateprefixmed">Est. between </span><span class="sfcday">Wednesday </span><span class="sfclongmonth">November </span><span class="sfcshortmonth">Nov </span><span class="sfcdate">11</span><span class="sfcordinal">th</span><span class="sfclongseparator"> and </span><span class="sfcshortseparator"> - </span><span class="sfcday">Tuesday </span><span class="sfclongmonth">December </span><span class="sfcshortmonth">Dec </span><span class="sfcdate">1</span><span class="sfcordinal">st</span></div>
        <div class="important forward">$0.00</div>
    </div>
</label>

How do I style .checkboxLabel when its child radio button is checked?

CaribouCode

If you restructure your HTML slightly you can do this with pure HTML and CSS. Something like this as a snippet:

HTML

<label for="ship-sfc-CNQM" class="radio">
  <input type="radio" name="shipping" value="sfc_CNQM" id="ship-sfc-CNQM" />
  <div class="radioStyle"></div>
  <span>Here is the text</span>
</label>

CSS

.radio input { display: none; }

.radio .radioStyle  { 
  display: inline-block;
  width:20px; height:20px;
  background: grey; }

.radio input:checked + .radioStyle { background: green; }

.radio span { display: inline-block; }

Here, you're using the :checked CSS selector to apply a rule to the following label field when it's selected.

Working fiddle: https://jsfiddle.net/w7tem94t/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to style a selected radio button AND include space as clickable?

From Dev

How to get the value of the checked radio button and the remaining td's but not include the radio button that has not been checked (in tr)

From Dev

HTML Checkbox as a Button - Include Label and Button as clickable area

From Dev

HTML Checkbox as a Button - Include Label and Button as clickable area

From Dev

How can I cleanly include an "Other" textbox in a radio button list in MVC?

From Dev

How to include HTML in button text

From Dev

How to include "span" and "class" with submit button?

From Dev

How to include scope parameters in Fb login button

From Dev

How to include an image or text inside a button?

From Dev

How to include a button within a form that does not act as the Submit button

From Dev

How to include an icon above some text on MDL button

From Dev

How to include a close button using jQuery toggle left to right?

From Dev

How to include Voting Button in Outlook Mail in VB.NET

From Dev

How can i include a jsp page depend on the button i choose

From Dev

How do I disable a button in an ng-include when a form in a sibling ng-include is $invalid?

From Dev

Include Button In Form Without Submitting

From Dev

Include Floating Action Button library

From Dev

How to include slide out menu on every page IOS (remove back button)

From Dev

Float action button anchor with include layout

From Dev

include layout android - causing issue with button background color

From Dev

Include a close button in a tab item dynamically using mvvm

From Dev

changing the content inside ng-include after click on a button/link

From Dev

Visual Studio 2013 Start button doesn't include browser choices

From Dev

changing the content inside ng-include after click on a button/link

From Dev

Resource ID of Button Defined Using Include Directive in Layout XML

From Dev

Where can I include the Google Analytics event tracking code on a button?

From Dev

div element containing ng-include and ng-controller dissappears after pressing back button on the browser

From Dev

Merging Users in Kinvey

From Dev

PostgreSQL: Efficiently split JSON array into rows

Related Related

  1. 1

    How to style a selected radio button AND include space as clickable?

  2. 2

    How to get the value of the checked radio button and the remaining td's but not include the radio button that has not been checked (in tr)

  3. 3

    HTML Checkbox as a Button - Include Label and Button as clickable area

  4. 4

    HTML Checkbox as a Button - Include Label and Button as clickable area

  5. 5

    How can I cleanly include an "Other" textbox in a radio button list in MVC?

  6. 6

    How to include HTML in button text

  7. 7

    How to include "span" and "class" with submit button?

  8. 8

    How to include scope parameters in Fb login button

  9. 9

    How to include an image or text inside a button?

  10. 10

    How to include a button within a form that does not act as the Submit button

  11. 11

    How to include an icon above some text on MDL button

  12. 12

    How to include a close button using jQuery toggle left to right?

  13. 13

    How to include Voting Button in Outlook Mail in VB.NET

  14. 14

    How can i include a jsp page depend on the button i choose

  15. 15

    How do I disable a button in an ng-include when a form in a sibling ng-include is $invalid?

  16. 16

    Include Button In Form Without Submitting

  17. 17

    Include Floating Action Button library

  18. 18

    How to include slide out menu on every page IOS (remove back button)

  19. 19

    Float action button anchor with include layout

  20. 20

    include layout android - causing issue with button background color

  21. 21

    Include a close button in a tab item dynamically using mvvm

  22. 22

    changing the content inside ng-include after click on a button/link

  23. 23

    Visual Studio 2013 Start button doesn't include browser choices

  24. 24

    changing the content inside ng-include after click on a button/link

  25. 25

    Resource ID of Button Defined Using Include Directive in Layout XML

  26. 26

    Where can I include the Google Analytics event tracking code on a button?

  27. 27

    div element containing ng-include and ng-controller dissappears after pressing back button on the browser

  28. 28

    Merging Users in Kinvey

  29. 29

    PostgreSQL: Efficiently split JSON array into rows

HotTag

Archive