How to add color to the radio?

2

I want to create a form and in it I want to include a sort of "option select" of radios in HTML, it should look like a semaphore:

  • 3 different colors indicating their values (good, fair and poor).

I've been researching and found about changing everyone, but I have not found anything about changing the color of each one, and hiding the 2 radio inside one.

    
asked by anonymous 01.11.2015 / 22:31

1 answer

3

Actually you can. With CSS3 several pseudo elements were created, with them we got a lot of flexibility and with a little creativity we can do exactly what you want.

See this example below, in it we hide the original html radius and recreate it with one using the pseudo-element: before.

Pretty simple ne? Hope it helps

label {
    display: inline-block;
    cursor: pointer;
    position: relative;
    padding-left: 25px;
    margin-right: 15px;
    font-size: 13px;
}

/* Escondemos o radio original */
input[type=radio] {
    display: none;
}

/* Usamos o pseudo-element :before para recriar o novo radio */
label:before {
    content: "";
    display: inline-block;
 
    width: 16px;
    height: 16px;
  
    border-radius:50%;
 
    margin-right: 10px;
    position: absolute;
    left: 0;
    bottom: 1px;
    background-color: #aaa;
    box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
}

/* CSS Responsavel por definir o estilo para radio Checkado */
input[type=radio]:checked + label:before {
    content: "22";
    color: #f3f3f3;
    font-size: 30px;
    text-align: center;
    line-height: 18px;
}
<div class="radio">
    <input id="male" type="radio" name="gender" value="male">
    <label for="male">Homem</label>
    <input id="female" type="radio" name="gender" value="female">
    <label for="female">Mulher</label>
</div>
    
02.11.2015 / 13:39