How to style a disabled radio button?
I have a set of radio buttons within a table cell. The table cell's background color differs from the page background.
Based on another input, I sometimes disable one or more radio buttons. When disabled, the interior of the radio button assumes the table cell's background. The circle coloring grays out a bit. This combines to make the button look like it "disappeared". Closer inspection shows it to still be there.
I've been struggling to define a CSS entry to change the appearance of the disabled radio button... can it be done? Currently, I'm doing something like this:
.radio {
backgrou开发者_C百科nd-color: #FFFFFF;
}
.radio:disabled {
background-color: #FFFFFF;
}
Will I have to resort to images?
UPDATE It's not the background that's the problem, but the interior of the button. When disabled the interior of the button takes on the background color of the table cell... ooh, here's an idea. I change both the table cell and the radio button.
You can use the CSS attribute selector [attributename]
for this.
.radio[disabled] {
background-color: #FFFFFF;
}
Maybe one solution is not disable anything and just
- Change the opacity
- Capture events and implement your own behaviour
Something like:
<input type="radio" name="i1" class="enabledinput" />
in your css write:
.disabledinput {
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
.enabledinput {
opacity: 1;
filter: alpha(opacity=100); /* For IE8 and earlier */
}
and then for example if you use jquery in your javascript write:
$(".enabledinput").each(function(i,obj) {
$(obj).click(function(evt) {
$(obj).removeClass("enabledinput");
$(obj).addClass("disabledinput");
/*do something here*/
});
});
An easy way to change the style of a disabled radio button is a simple absolute positioned overlay with the :after attribute. You can adjust the background color and borders as you see fit.
input[disabled] {
position: relative;
height:15px;
width: 15px;
box-sizing: border-box;
margin: 0;
&:after {
position: absolute;
content: '';
display: block;
width: 100%;
height: 100%;
border-radius: 50%;
background-color:red;
}
}
here is an example pen https://codepen.io/Cuberic/pen/PmQoVd
Try adding the border colour as i believe thats the initial edge styling.
border-color #ffffff;
Also you might want to set the border to have no edge styling.
border: 0px solid #ffffff;
Or something along them lines!
Replace them with background images.
精彩评论