lab-css

器で変わる札

同じ一枚の札が、器(コンテナ)の幅によって花札風と短冊風にレイアウトを変える。リサイズハンドルはCSSのresizeプロパティのみで実現。

全画面で見る
Container Queriesresize操作: クリック

枠の右下ハンドルをドラッグして幅を変えられます

枠の右下ハンドルをドラッグして、器の幅を変えてください

芒に月

同じ一枚の札が、器の幅で花札風と短冊風に姿を変えます。

container query

お使いのブラウザはコンテナクエリに未対応のため、札のレイアウトは変化しません。

対応ブラウザ

CSS機能Chrome / EdgeFirefoxSafari備考
Container Queries106+110+16.0+Baseline(cqw/cqh単位を含む)
resize対応対応対応CSSのみのリサイズハンドル

コード

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

/* 器で変わる札: コンテナ幅で花札風/短冊風に切り替わる。
   リサイズハンドルはCSSのresizeプロパティのみ */

.work-container-cards {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  padding: 24px;
  background:
    radial-gradient(80% 60% at 50% 0%, rgba(242, 165, 184, 0.06), transparent 70%),
    #0e0f16;
}

.cc-hint {
  margin: 0;
  color: rgba(235, 235, 240, 0.55);
  font-size: 12px;
  text-align: center;
}

/* 器: この要素自身がコンテナかつリサイズ可能 */
.cc-resize {
  container-type: inline-size;
  container-name: card-vessel;
  resize: horizontal;
  overflow: auto;
  width: min(72%, 560px);
  min-width: 190px;
  max-width: 100%;
  padding: 18px;
  border: 1px dashed rgba(242, 165, 184, 0.35);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
}

/* ---- 札(デフォルト: 短冊風の縦長レイアウト) ---- */

.cc-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  min-height: 300px;
  border-radius: 10px;
  border: 2px solid #3a2530;
  background: linear-gradient(165deg, #1d1420 0%, #241127 100%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.cc-art {
  position: relative;
  overflow: hidden;
  min-height: 55cqw;
  max-height: 200px;
  background: linear-gradient(180deg, #241b3a 0%, #12101f 100%);
}

.cc-moon {
  position: absolute;
  top: 12%;
  right: 14%;
  width: 34cqw;
  max-width: 110px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff4d8, #f0c86a);
  box-shadow: 0 0 30px rgba(240, 200, 106, 0.55);
}

.cc-cloud {
  position: absolute;
  bottom: 18%;
  left: -6%;
  width: 70%;
  height: 18%;
  border-radius: 999px;
  background: rgba(120, 96, 160, 0.45);
  filter: blur(2px);
}

.cc-grass {
  position: absolute;
  bottom: -4%;
  width: 3cqw;
  min-width: 5px;
  max-width: 10px;
  height: 42%;
  border-radius: 999px 999px 0 0;
  background: linear-gradient(180deg, #c8b988, #6b5e3c);
  transform-origin: bottom;
}

.cc-g1 { left: 18%; transform: rotate(-10deg); }
.cc-g2 { left: 30%; height: 52%; transform: rotate(-2deg); }
.cc-g3 { left: 42%; height: 36%; transform: rotate(8deg); }

.cc-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
}

/* 短冊らしく縦書きの題字 */
.cc-title {
  margin: 0;
  writing-mode: vertical-rl;
  align-self: center;
  color: #f5e6c8;
  font-size: clamp(18px, 9cqw, 30px);
  font-weight: 700;
  letter-spacing: 0.35em;
}

.cc-text {
  margin: 0;
  color: rgba(235, 226, 210, 0.6);
  font-size: clamp(10px, 3.4cqw, 13px);
  line-height: 1.8;
}

.cc-tag {
  align-self: flex-start;
  padding: 2px 10px;
  border: 1px solid rgba(242, 165, 184, 0.4);
  border-radius: 999px;
  color: #f2a5b8;
  font-family: monospace;
  font-size: 10px;
}

/* ---- 器が広いとき: 花札風の横長レイアウト ---- */

@container card-vessel (min-width: 420px) {
  .cc-card {
    flex-direction: row;
    min-height: 240px;
  }

  .cc-art {
    flex: 1.2;
    min-height: 0;
    max-height: none;
  }

  .cc-moon {
    width: 22cqw;
    max-width: 150px;
  }

  .cc-body {
    flex: 1;
    justify-content: center;
    gap: 12px;
    padding: 20px;
  }

  .cc-title {
    writing-mode: horizontal-tb;
    align-self: flex-start;
    font-size: clamp(22px, 6cqw, 34px);
    letter-spacing: 0.18em;
  }
}

/* ---- コンテナクエリ非対応ブラウザへの告知 ---- */

@supports not (container-type: inline-size) {
  .work-container-cards .work-warn {
    display: block;
  }
}