lab-css

ネオンの雨

都市夜景にネオン光の雨が降りしきる。@propertyで型付けした角度カスタムプロパティをアニメーションし、conic-gradientの看板とhue-rotateで色相が巡る。

全画面で見る
@propertyconic-gradient()hue-rotate()操作: 鑑賞のみ

対応ブラウザ

CSS機能Chrome / EdgeFirefoxSafari備考
@property85+128+16.4+Baseline
conic-gradient()対応対応対応全主要ブラウザ対応
hue-rotate()対応対応対応全主要ブラウザ対応

コード

表示中のコードは作品の実行に使われているものと同一ソースです。そのままコピーして試せます。

/* ネオンの雨: @propertyで型付けした角度を回し、街のネオンの色相が巡る */

@property --nr-hue {
  syntax: "<angle>";
  inherits: true;
  initial-value: 0deg;
}

.work-neon-rain {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05060f;
  animation: nr-cycle 24s linear infinite;
}

/* 型付きカスタムプロパティなので、この1本のアニメーションだけで
   看板と反射の色相が連続的に補間される */
@keyframes nr-cycle {
  to {
    --nr-hue: 360deg;
  }
}

.nr-sky {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 90% at 70% -20%, rgba(84, 48, 128, 0.55), transparent 60%),
    radial-gradient(80% 60% at 20% 0%, rgba(28, 60, 120, 0.45), transparent 65%),
    linear-gradient(180deg, #060714 0%, #0a0c22 55%, #150f31 100%);
}

/* ビル群: 窓明かりのグリッドをスカイライン形状でクリップ */
.nr-city {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    repeating-linear-gradient(90deg,
      rgba(255, 205, 130, 0.2) 0 4px, transparent 4px 22px),
    repeating-linear-gradient(0deg,
      rgba(255, 205, 130, 0.16) 0 4px, transparent 4px 18px),
    linear-gradient(180deg, #0d1023, #06070f);
}

.nr-city-back {
  height: 62%;
  opacity: 0.55;
  clip-path: polygon(
    0% 100%, 0% 38%, 7% 38%, 7% 18%, 12% 18%, 12% 44%, 18% 44%,
    18% 8%, 21% 8%, 21% 3%, 23% 3%, 23% 8%, 27% 8%, 27% 36%,
    34% 36%, 34% 22%, 41% 22%, 41% 48%, 48% 48%, 48% 12%, 55% 12%,
    55% 40%, 61% 40%, 61% 26%, 68% 26%, 68% 6%, 71% 6%, 71% 30%,
    78% 30%, 78% 44%, 85% 44%, 85% 16%, 92% 16%, 92% 34%, 100% 34%,
    100% 100%
  );
}

.nr-city-front {
  height: 44%;
  clip-path: polygon(
    0% 100%, 0% 52%, 9% 52%, 9% 24%, 16% 24%, 16% 58%, 24% 58%,
    24% 34%, 30% 34%, 30% 14%, 33% 14%, 33% 34%, 40% 34%, 40% 62%,
    50% 62%, 50% 28%, 58% 28%, 58% 46%, 66% 46%, 66% 18%, 74% 18%,
    74% 54%, 82% 54%, 82% 38%, 90% 38%, 90% 60%, 100% 60%, 100% 100%
  );
}

/* ネオン看板: conic-gradientのリング。hue-rotateで色相が巡る */
.nr-sign {
  position: absolute;
  top: 14%;
  right: 12%;
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(from 20deg,
    #ff5e8a, #b06bff, #35d6ff, #7dffce, #ffd166, #ff5e8a);
  -webkit-mask: radial-gradient(circle,
    transparent 0 56%, #000 58% 74%, transparent 76% 84%, #000 86% 100%);
  mask: radial-gradient(circle,
    transparent 0 56%, #000 58% 74%, transparent 76% 84%, #000 86% 100%);
  filter: hue-rotate(var(--nr-hue)) drop-shadow(0 0 22px rgba(255, 94, 138, 0.55));
  opacity: 0.9;
}

/* 雨: 縦に流れる光の筋をタイル状に敷き、maskで細い雨脚に切り出して
   transformで落とす */
.nr-rain {
  position: absolute;
  left: -10%;
  right: -10%;
  top: -100%;
  height: 200%;
  pointer-events: none;
  background-image: linear-gradient(to bottom,
    transparent 0%, rgba(150, 200, 255, 0.4) 78%, rgba(210, 235, 255, 0.7) 96%,
    transparent 100%);
  background-repeat: repeat;
  -webkit-mask: repeating-linear-gradient(90deg,
    #000 0 2px, transparent 2px var(--gap, 70px));
  mask: repeating-linear-gradient(90deg,
    #000 0 2px, transparent 2px var(--gap, 70px));
}

.nr-rain-1 {
  --gap: 74px;
  background-size: 100% 130px;
  transform: rotate(7deg);
  animation: nr-fall 0.9s linear infinite;
  opacity: 0.75;
}

.nr-rain-2 {
  --gap: 110px;
  background-size: 100% 190px;
  background-position: 0 60px;
  -webkit-mask-position: 37px 0;
  mask-position: 37px 0;
  transform: rotate(9deg);
  animation: nr-fall 1.4s linear infinite;
  opacity: 0.5;
}

.nr-rain-3 {
  --gap: 52px;
  background-size: 100% 90px;
  background-position: 0 30px;
  -webkit-mask-position: 19px 0;
  mask-position: 19px 0;
  transform: rotate(6deg);
  animation: nr-fall 0.65s linear infinite;
  opacity: 0.55;
}

@keyframes nr-fall {
  to {
    translate: 0 50%;
  }
}

/* 路面の反射とネオンの靄 */
.nr-mist {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 30%;
  background:
    radial-gradient(60% 120% at 78% 100%, rgba(255, 94, 138, 0.28), transparent 70%),
    radial-gradient(50% 100% at 25% 100%, rgba(53, 214, 255, 0.2), transparent 70%),
    linear-gradient(0deg, rgba(10, 8, 24, 0.9), transparent);
  filter: hue-rotate(var(--nr-hue));
}

/* 動きへの配慮: 停止し、CSSのみのチェックボックスでオプトイン再生 */
@media (prefers-reduced-motion: reduce) {
  .work-neon-rain,
  .work-neon-rain * {
    animation-play-state: paused !important;
  }

  .work-neon-rain .motion-optin {
    display: inline-flex;
  }

  .work-neon-rain:has(.motion-optin input:checked),
  .work-neon-rain:has(.motion-optin input:checked) * {
    animation-play-state: running !important;
  }
}