Код IT
← Каталог

Типовые элементы интерфейса — Переключатель темы и `:has()`

Фрагмент из «Типовые элементы интерфейса»: Переключатель темы и `:has()`.

CSS main.css
.theme-panel {
  padding: 2rem;
  border-radius: 12px;
  background: #f8f9fa;
  color: var(--color-dark);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.theme-panel:has(.switch__input:checked) {
  background: var(--color-dark);
  color: #f8f9fa;
}

.switch__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .theme-panel,
  .switch-track,
  .switch-track::before {
    transition: none;
  }
}
.theme-panel {
  padding: 2rem;
  border-radius: 12px;
  background: #f8f9fa;
  color: var(--color-dark);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.theme-panel:has(.switch__input:checked) {
  background: var(--color-dark);
  color: #f8f9fa;
}

.switch__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .theme-panel,
  .switch-track,
  .switch-track::before {
    transition: none;
  }
}