Mikołaj Popieluch Mikołaj Popieluch - 1 year ago 87
CSS Question

Styling Radio inputs issue

I want to style radio input INSIDE "label" tags. I already changed the background color, however when im clicking on my radio white dot inside doesn't show up. I wrote a code for that and I really don't know what the problem is.

<!DOCTYPE html>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
label {
display: inline-block;
cursor: pointer;
position: relative;
padding-left: 25px;
margin-right: 15px;
font-size: 13px;

input[type=radio] {
display: none;

label:before {
content: "";
display: inline-block;
width: 17px;
height: 17px;
margin-right: 10px;
position: absolute;
left: 0;
bottom: 1px;
background-color: #ff7900;
box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
border-radius: 8px;

input[type=radio]:checked + label:before {
content: "\2022";
color: #f3f3f3;
font-size: 30px;
text-align: center;
line-height: 18px;
position: absolute;

.input {
font-size: 20px;
font-weight: bold;
<label class="input"><input type="radio" name="number" class="hehe">xxxxxxxx</label>
<label class="input" ><input type="radio" name="number" class="hehe">xxxxxxx</label>
<label class="input"><input type="radio" name="number" class="hehe">xxxxxxx</label>\
<label class="input"><input type="radio" name="number" class="hehe">xxxxxxx</label>

Answer Source


input[type=radio]:checked + label:before

requires that the label immediately follow the input.

However, your HTML is

 <label class="input"><input type="radio" name="number" class="hehe">xxxxxxxx</label>

The label surrounds the input and so the selector will not work.

You would need

<input type="radio" name="number" class="hehe"/><label class="input">xxxxxxxx</label>

Alternatively; use a pseudo-element on a span inside the label rather than the label itself

 <label class="input">
   <input type="radio" name="number" class="hehe">


input[type=radio]:checked + span:before
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download