Radio Button Styling

14,252

Solution 1

You can use a CSS2 selector trick to connect to a radio group and display other stuff immediately after.

See: http://jsfiddle.net/7kScn/1/

It's just a basic example, but it operates on the premise of hiding the input field and then styling the label immediately after it, giving it the effect that it's the actual thing you're checking.

Solution 2

Is this of use? input[type=radio]:checked { border: 1px solid black; }

Share:
14,252
henryaaron
Author by

henryaaron

Updated on August 09, 2022

Comments

  • henryaaron
    henryaaron almost 2 years

    I want to style radio buttons with pure CSS, no classes or IDs. Just input[type=radio]. I want to use a background image for unselected and selected. However, the -vendor-appearance:none; doesn't work with Trident or Gecko. Just Webkit. In those browsers you can see the background image as a background to the radio button but the button is still there rather than just displaying the image, how can I get rid of the button so just the background image displays. The fiddle: http://jsfiddle.net/7kScn/

  • henryaaron
    henryaaron over 12 years
    CSS3? :( it's an ecommerce site, none of the functionality can be based on CSS3 just the style. If it falls back to just display the checkboxes like it normally would than that's acceptable, but if you're calling display:none; than I can't really use that.
  • animuson
    animuson over 12 years
    According to this compatibility chart, this specific selector should work fine in its current state. It's only unsupported in IE6 (those notes about static for IE7/8 don't affect this use of it). It appears to have been CSS2 (?).
  • henryaaron
    henryaaron over 12 years
    But my site doesn't use labels, how would it work without the + label
  • animuson
    animuson over 12 years
    You can't remove the actual box from them with CSS, that is what the radio/checkbox is. The only other solution would be to use JavaScript to modify the HTML there to make them fancy.
  • henryaaron
    henryaaron over 12 years
    Just checked with Adobe BrowserLab, works in IE7 + in IE6 falls back to standard visibility. That's great, now what about the labels is there a workaround?