I mean, a radio button itself consists of a round shape and a dot at the center (when the button is selected). What I want to change is the color of both. Can this be done using CSS?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
As Fred mentioned, there is no way to natively style radio buttons in regards to color, size, etcc. But you can use CSS Pseudo elements to setup an impostor of any given radio button, and style it. Touching on what JamieD said, on how we can use the :after Pseudo element, you can use both :before and :after to achieve a desirable look.
Benefits of this approach:
Explanation of short demo below:
The HTML
The CSS
A Quick Demo to see it in action
In conclusion, no JavaScript, images or batteries required. Pure CSS.
simple cross browser custom radio button example for you
https://jsfiddle.net/kuzroman/ae1b34ay/
you can use the checkbox hack as explained in css tricks
http://css-tricks.com/the-checkbox-hack/
working example of radio button:
http://codepen.io/Angelata/pen/Eypnq
Works in IE9+, Firefox 3.5+, Safari 1.3+, Opera 6+, Chrome anything.
Try this css with transition:
Demo
Html :
You can achieve customized radio buttons in two pure CSS ways
Via removing standard appearance using CSS
appearance
and applying custom appearance. Unfortunately this was doesn't work in IE for Desktop (but works in IE for Windows Phone). Demo:Via hiding radiobutton and setting custom radiobutton appearance to
label
's pseudoselector. By the way no need for absolute positioning here (I see absolute positioning in most demos). Demo:It may be helpful to bind radio-button to styled label. Futher details in this answer.