ГлавнаяHTML/CSS → Красивая стилизация Radio кнопок на чистом CSS
HTML/CSS

Красивая стилизация Radio кнопок на чистом CSS

Красивая стилизация Radio кнопок на чистом CSS
Подпишись на нас в телеграм @coderoll

Чтобы Ваш сайт был круче конкурентов, всегда необходимо вносить какие то новшества. Как вариант, можете стилизовать радио кнопки с помощью CSS всего в 2 шага.


Шаг 1.

Добавляем HTML код в нужное вам место на сайте

<div class="tabs">
  <input type="radio" id="radio-1" name="tabs" checked />
  <label class="tab" for="radio-1">Upcoming<span class="notification">2</span></label>
  <input type="radio" id="radio-2" name="tabs" />
  <label class="tab" for="radio-2">Development</label>
  <input type="radio" id="radio-3" name="tabs" />
  <label class="tab" for="radio-3">Completed</label>
  <span class="glider"></span>
</div>


Шаг 2.

Добавляем CSS код в ваш файл стилей

:root {
  --primary-color: #185ee0;
  --secondary-color: #e6eef9;
}

*,
*:after,
*:before {
  box-sizing: border-box;
}

.tabs {
  display: -webkit-box;
  display: flex;
  position: relative;
  background-color: #fff;
  box-shadow: 0 0 1px 0 rgba(24, 94, 224, 0.15), 0 6px 12px 0 rgba(24, 94, 224, 0.15);
  padding: 0.75rem;
  border-radius: 99px;
}

.tabs * {
  z-index: 2;
}

input[type="radio"] {
  display: none;
}

.tab {
  display: -webkit-box;
  display: flex;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: center;
  justify-content: center;
  height: 54px;
  width: 200px;
  font-size: 1.25rem;
  font-weight: 500;
  border-radius: 99px;
  cursor: pointer;
  -webkit-transition: color 0.15s ease-in;
  transition: color 0.15s ease-in;
}

.notification {
  display: -webkit-box;
  display: flex;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  margin-left: 0.75rem;
  border-radius: 50%;
  background-color: var(--secondary-color);
  -webkit-transition: 0.15s ease-in;
  transition: 0.15s ease-in;
}

input[type="radio"]:checked+label {
  color: var(--primary-color);
}

input[type="radio"]:checked+label>.notification {
  background-color: var(--primary-color);
  color: #fff;
}

input[id="radio-1"]:checked~.glider {
  -webkit-transform: translateX(0);
  transform: translateX(0);
}

input[id="radio-2"]:checked~.glider {
  -webkit-transform: translateX(100%);
  transform: translateX(100%);
}

input[id="radio-3"]:checked~.glider {
  -webkit-transform: translateX(200%);
  transform: translateX(200%);
}

.glider {
  position: absolute;
  display: -webkit-box;
  display: flex;
  height: 54px;
  width: 200px;
  background-color: var(--secondary-color);
  z-index: 1;
  border-radius: 99px;
  -webkit-transition: 0.25s ease-out;
  transition: 0.25s ease-out;
}
Добавить комментарий
Кликните на изображение чтобы обновить код, если он неразборчив