@date_step_end

Почему не работает input type="radio"?

У input с атрибутом checked, отображается как задумывалось, но не получается переключиться на другую кнопку.

<div class="product__radio-btns">
                    <input type="radio" name="radios">
                    <span class="custom-radio" style="--radio-color: rgba(255, 255, 255, 1)"></span>
                    
                    <input type="radio" name="radios" checked>
                    <span class="custom-radio" style="--radio-color: rgba(0, 0, 0, 1)"></span> 
                    
                    <input type="radio" name="radios">
                    <span class="custom-radio" style="--radio-color: rgba(9, 15, 151, 1)"></span>

                    <input type="radio" name="radios">
                    <span class="custom-radio" style="--radio-color: rgba(239, 205, 152, 1)"></span>
        </div>

.product__radio-btns {
    display: flex;
    gap: 6px;
}

.product__radio-btns input[type="radio"] {
  display: none;
}

.custom-radio {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 1px solid white;
    border-radius: 50%;
    cursor: pointer;
    position: relative;
}

.custom-radio::before {
    content: '';
    display: block;
    width: 6px; 
    height: 6px; 
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); 
    transition: background-color 0.3s;
    background-color: var(--radio-color);
}

input[type="radio"]:checked + .custom-radio {
    border-color: var(--radio-color);
}
  • Вопрос задан
  • 166 просмотров
Решения вопроса 1
@apoca1ipsis
В label оберните
<label>
      <input type="radio" name="radios">
      <span class="custom-radio" style="--radio-color: rgba(255, 255, 255, 1)"></span>
    </label>
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы