How to customize radio button in html
Just add the :before
pseudo element to take care of the color before the radio
button is checked. You could add this to your CSS
:
.regular-radio + label:before {
background: none repeat scroll 0 0 #FDFDFD;
border-radius: 50px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3) inset;
content: " ";
font-size: 36px;
height: 8px;
left: 7px;
position: absolute;
top: 7px;
width: 8px;
}
Working demo. You can ofcourse change the background
of this label to match exactly the example you show. Hope it helps.
How do I change the color of radio buttons?
A radio button is a native element specific to each OS/browser. There is no way to change its color/style, unless you want to implement custom images or use a custom Javascript library which includes images (e.g. this - cached link)
Custom style radiobuttons
You can hide the input itself with display:none
and the use a pseudo-element on the label
input[type='radio'] {display: none;}
input[type='radio'] + label { position: relative; line-height: 1em;}
input[type='radio'] + label:before { content: ''; width: .5em; height: .5em; border-radius:100%; margin-right: .5em; display: inline-block; background: red; vertical-align: middle; box-shadow: 0 0 0 .1em white, 0 0 0 .2em black;}
input[type='radio']:checked + label:before { background: green; vertical-align: middle;}
<span class="custom-radio"> <input id="id4" type="radio" name="id_test" value=""/> <label for="id4">No</label></span>
How to change the style of radio button in FireFox?
I like Sato's answer, but you could also add this to your CSS:
input[type='radio'] {
-moz-appearance: initial !important;
}
I'd try to avoid using !important
in your CSS, it's not a good practice to use. I think if you remove it from your code, you could probably remove it from my snippet.
why my CSS custom radio button doesn't work?
Update the code as follows.
.radio {
display: flex;
align-items: center;
margin-left: 5px;
position: relative;
padding-left: 22px;
margin-bottom: 10px;
cursor: pointer;
}
.radio input[type="radio"] {
position: absolute;
opacity: 0;
z-index: -1;
}
.radio span {
width: 18px;
height: 18px;
background-color: rgba(255, 255, 255, 1);
border: 1px solid #484848;
border-radius: 50%;
position: absolute;
display: inline-block;
left: 0;
}
.radio span::after {
content: "";
width: 16px;
height: 16px;
background-color: #448899;
border-radius: 50%;
display: inline-block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0);
}
.radio input[type="radio"]:checked ~ span::after {
transform: translate(-50%, -50%) scale(1);
}
<label class="radio">
<input type="radio" name="time" value="2000" id="morning" required />
<span></span>
上半天
</label>
<label class="radio">
<input type="radio" name="time" value="2500" id="afternoon" />
<span></span>
下半天
</label>
Related Topics
Cross-Browser CSS3 Keyframe Animation Firefox
Force Elements to Be Horizontally Aligned
Media Queries and Device Orientation Change
Pass SASS List to Mixin with Multiple Arguments
Syntax Highlighting in Jekyll Using Redcarpet
Change Colour Navbar Header Ionic 2
Webgrease Error on Styles.Render Call in _Layout.Cshtml in MVC4
CSS Background Color Keyframes Animation
How to Animate Infinite Marker Movement Down an Svg Path Without Very High CPU Usage
What Is a Parse Error and How to Fix It
How to Include Caption for Gallery Using Magnific Popup
Lato Font Missing Letters in Ie and Firefox
Overflow:Hidden Not Working as Expected in Google Chrome
How to Have an Image Placeholder in Angularjs
How to Change Img Src Attribute Using CSS
How to Make The Background Div Only Transparent Using CSS
Responsive Design: Centralize a Full-Screen Square in Any Screen Size