There are other ways to target an element in CSS outside of a class ID. A few examples are attribute selectors (name="something"
for example), :nth-child()
, or :nth-of-type()
. It's worth noting that it's difficult to change the color of radio input buttons. You're usually better off hiding the input and linking the input to a label via the for
attribute on a label and an id
on the input, then styling the label instead.
input[name="attribute_pa_size_thinoptics"] {
margin-left: 5em;
}
input:nth-child(2) {
margin-left: 10em;
}
input[type="radio"]:nth-of-type(1) {
margin-left: 15em;
}
<table class="variations" cellspacing="0">
<tbody>
<tr>
<td class="label"><label for="pa_size_thinoptics">Size</label></td>
<td class="value">
<div class="vari-option fix"><label for="attribute_pa_size_thinoptics">1.0</label><input type="radio" name="attribute_pa_size_thinoptics" value="1-0" checked="checked"></div>
<div class="vari-option fix"><label for="attribute_pa_size_thinoptics">1.5</label><input type="radio" name="attribute_pa_size_thinoptics" value="1-5"></div>
<div class="vari-option fix"><label for="attribute_pa_size_thinoptics">2.0</label><input type="radio" name="attribute_pa_size_thinoptics" value="2"></div>
<div class="vari-option fix"><label for="attribute_pa_size_thinoptics">2.5</label><input type="radio" name="attribute_pa_size_thinoptics" value="2-5"></div>
</td>
</tr>
<tr>
<td class="label"><label for="pa_thin-color">Color</label></td>
<td class="value">
<div class="vari-option fix"><label for="attribute_pa_thin-color">Black</label><input type="radio" name="attribute_pa_thin-color" value="black" checked="checked"></div>
<div class="vari-option fix"><label for="attribute_pa_thin-color">Blue</label><input type="radio" name="attribute_pa_thin-color" value="blue"></div>
<div class="vari-option fix"><label for="attribute_pa_thin-color">Purple</label><input type="radio" name="attribute_pa_thin-color" value="purple"></div>
<div class="vari-option fix"><label for="attribute_pa_thin-color">Red</label><input type="radio" name="attribute_pa_thin-color" value="red"></div>
<div class="vari-option fix"><label for="attribute_pa_thin-color">White</label><input type="radio" name="attribute_pa_thin-color" value="crystal-clear"></div>
</td>
</tr>
</tbody>
</table>
Here's an example of how you style the label instead of the input.
input {
display: none;
}
label {
display: block;
width: 1em; height: 1em;
border-radius: 50%;
margin: 0 0 1em;
border: 1px solid #333;
transition: padding .25s;
}
.error {
background: red;
}
.success {
background: green;
}
input:checked + label {
padding: .25em;
}
<input type="radio" id="radio" name="foo"><label for="radio" class="error"></label>
<input type="radio" id="radio2" name="foo"><label for="radio2" class="success"></label>