skip to Main Content
<!-- This is my html input tag -->
 <input class="custom-radio" type="radio" name="selected_center" value="{{center.id}}"
                    id="selected_center_{{center.id}}">

<!-- Only CSS I am using for my custom color using accent property but cant change the color on hover -->
 input[type='radio'] {
        accent-color: #0098ff;
    }

I have used hover property with input radio tag but not working.

3

Answers


  1. Not sure why you would want to do this, but you can do it.

    body {
      margin: 1em;
      font-family: sans-serif;
    }
    .custom-radio>label {
      display: block;
      font-size: 1.5em;
      margin: 0.25em 0;
    }
    
    .custom-radio>label>input[type=radio] {
      transform: scale(2);
      vertical-align: middle;
      margin-right: 1em;
    }
    
    .custom-radio>label:nth-child(1)>input[type=radio] {
      accent-color: red;
    }
    
    .custom-radio>label:nth-child(2)>input[type=radio] {
      accent-color: darkorange;
    }
    
    .custom-radio>label:nth-child(3)>input[type=radio] {
      accent-color: green;
    }
    
    .custom-radio>label:hover {
      color: blue;
    }
    
    .custom-radio>label:hover>input[type=radio] {
      accent-color: blue;
    }
    
    .custom-radio>label>input[type=radio]:not(:checked) {
      cursor: pointer;
    }
    <div class="custom-radio">
      <label><input type="radio" name="radio1"> Stop</label>
      <label><input type="radio" name="radio1"> Wait</label>
      <label><input type="radio" name="radio1"> Go</label>
    </div>
    Login or Signup to reply.
  2. One of the ways to achieve this is by creating a custom radio button instead. I’ve attached a snippet to demonstrate this. You could style the .checkmark:after { background-color: #2196F3; } and .container .checkmark:after { background-color: #2196F3; } properties for example to change the buttons color.

    Source: custom radio buttons and checkboxes

    .container {
      display: block;
      position: relative;
      padding-left: 35px;
      margin-bottom: 12px;
      cursor: pointer;
      font-size: 22px;
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;
    }
    .container input {
      position: absolute;
      opacity: 0;
      cursor: pointer;
    }
    .checkmark {
      position: absolute;
      top: 0;
      left: 0;
      height: 25px;
      width: 25px;
      background-color: #eee;
      border-radius: 50%;
    }
    .container:hover input ~ .checkmark {
      background-color: #ccc;
    }
    .container input:checked ~ .checkmark {
      background-color: #2196F3;
    }
    .checkmark:after {
      content: "";
      position: absolute;
      display: none;
    }
    .container input:checked ~ .checkmark:after {
      display: block;
    }
    .container .checkmark:after {
        top: 9px;
        left: 9px;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: white;
    }
    <label class="container">One
      <input type="radio" checked="checked" name="radio">
      <span class="checkmark"></span>
    </label>
    <label class="container">Two
      <input type="radio" name="radio">
      <span class="checkmark"></span>
    </label>
    <label class="container">Three
      <input type="radio" name="radio">
      <span class="checkmark"></span>
    </label>
    <label class="container">Four
      <input type="radio" name="radio">
      <span class="checkmark"></span>
    </label>
    Login or Signup to reply.
  3.  input[type='radio'] {
            accent-color: #0098ff;
        }
     input[type='radio']:hover {
            accent-color: red;
        }
    <input class="custom-radio" type="radio" name="selected_center" value="{{center.id}}" id="selected_center_{{center.id}}" checked>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search