09:has 기반 필터 탭
숨겨진 라디오 버튼과 :has() 셀렉터만으로 탭을 누르면 카테고리가 다른 타일은 옅어지고 줄어들며, 인디케이터는 고정 폭의 정확한 배수로 미끄러집니다.
쓰임포트폴리오 카테고리 필터
:has()translateXJS 8줄

<main class="stage">
<div class="ft-frame is-demo">
<input type="radio" name="ft-cat" id="ft-1" class="ft-radio" checked>
<input type="radio" name="ft-cat" id="ft-2" class="ft-radio">
<input type="radio" name="ft-cat" id="ft-3" class="ft-radio">
<div class="ft-tabs">
<span class="ft-indicator" aria-hidden="true"></span>
<label class="ft-tab" for="ft-1">All</label>
<label class="ft-tab" for="ft-2">Photo</label>
<label class="ft-tab" for="ft-3">Video</label>
</div>
<div class="ft-gallery">
<div class="ft-tile" data-cat="photo"></div>
<div class="ft-tile" data-cat="video"></div>
<div class="ft-tile" data-cat="photo"></div>
<div class="ft-tile" data-cat="video"></div>
<div class="ft-tile" data-cat="photo"></div>
<div class="ft-tile" data-cat="video"></div>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-base;
$easing: $ease-pop;
$color: $subject-blue;
@include stage($stage-ink);
.ft-frame { width: min(260px, 78vw); }
.ft-radio { position: absolute; opacity: 0; pointer-events: none; }
.ft-tabs {
position: relative;
display: flex;
gap: 0;
width: fit-content;
padding: $sp-1;
margin-bottom: $sp-2;
background: rgba(255, 255, 255, .1);
border-radius: $r-pill;
}
// 탭은 내용 폭이 아니라 고정 64px — 인디케이터의 translateX 가 이 값의 정확한 배수가 되게 한다(BD19)
.ft-tab {
position: relative; z-index: 1;
flex: 0 0 64px;
text-align: center;
padding: $sp-2 0;
font: 600 12px/1 -apple-system, "Segoe UI", sans-serif;
color: $subject-cream;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.ft-indicator {
position: absolute; top: $sp-1; bottom: $sp-1; left: $sp-1;
width: 64px;
border-radius: $r-pill;
background: $color;
transform: translateX(0);
transition: transform $duration $easing;
}
#ft-1:checked ~ .ft-tabs .ft-indicator { transform: translateX(0); }
#ft-2:checked ~ .ft-tabs .ft-indicator { transform: translateX(64px); }
#ft-3:checked ~ .ft-tabs .ft-indicator { transform: translateX(128px); }
.ft-gallery {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: $sp-2;
}
.ft-tile {
aspect-ratio: 4 / 3;
border-radius: $r-sm;
transition: opacity $duration $easing, transform $duration $easing;
}
.ft-tile[data-cat="photo"] { background: radial-gradient(30px circle at 35% 35%, rgba(255,255,255,.55), transparent 60%), linear-gradient(150deg, $subject-blue, $subject-ink); }
.ft-tile[data-cat="video"] { background: radial-gradient(30px circle at 60% 40%, rgba(255,255,255,.55), transparent 60%), linear-gradient(150deg, $subject-cream, $subject-blue); }
// 실사용: JS 0줄 — 숨긴 라디오와 :has() 만으로 다른 카테고리 타일이 옅어지고 줄어든다
// (.ft-frame 이 공통 조상 — 라디오와 갤러리는 형제라 :has() 로 라디오의 :checked 를 먼저 확인해야 한다)
.ft-frame:has(#ft-2:checked) .ft-tile:not([data-cat="photo"]) { opacity: .15; transform: scale(.94); pointer-events: none; }
.ft-frame:has(#ft-3:checked) .ft-tile:not([data-cat="video"]) { opacity: .15; transform: scale(.94); pointer-events: none; }
@media (prefers-reduced-motion: reduce) {
.ft-indicator, .ft-tile { transition: none !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.ft-frame {
width: min(260px, 78vw);
}
.ft-radio {
position: absolute;
opacity: 0;
pointer-events: none;
}
.ft-tabs {
position: relative;
display: flex;
gap: 0;
width: fit-content;
padding: 4px;
margin-bottom: 8px;
background: rgba(255, 255, 255, 0.1);
border-radius: 999px;
}
.ft-tab {
position: relative;
z-index: 1;
flex: 0 0 64px;
text-align: center;
padding: 8px 0;
font: 600 12px/1 -apple-system, "Segoe UI", sans-serif;
color: #fff7e6;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.ft-indicator {
position: absolute;
top: 4px;
bottom: 4px;
left: 4px;
width: 64px;
border-radius: 999px;
background: #2f6df6;
transform: translateX(0);
transition: transform 300ms cubic-bezier(0.2, 1.4, 0.4, 1);
}
#ft-1:checked ~ .ft-tabs .ft-indicator {
transform: translateX(0);
}
#ft-2:checked ~ .ft-tabs .ft-indicator {
transform: translateX(64px);
}
#ft-3:checked ~ .ft-tabs .ft-indicator {
transform: translateX(128px);
}
.ft-gallery {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.ft-tile {
aspect-ratio: 4/3;
border-radius: 8px;
transition: opacity 300ms cubic-bezier(0.2, 1.4, 0.4, 1), transform 300ms cubic-bezier(0.2, 1.4, 0.4, 1);
}
.ft-tile[data-cat=photo] {
background: radial-gradient(30px circle at 35% 35%, rgba(255, 255, 255, 0.55), transparent 60%), linear-gradient(150deg, #2f6df6, #17141a);
}
.ft-tile[data-cat=video] {
background: radial-gradient(30px circle at 60% 40%, rgba(255, 255, 255, 0.55), transparent 60%), linear-gradient(150deg, #fff7e6, #2f6df6);
}
.ft-frame:has(#ft-2:checked) .ft-tile:not([data-cat=photo]) {
opacity: 0.15;
transform: scale(0.94);
pointer-events: none;
}
.ft-frame:has(#ft-3:checked) .ft-tile:not([data-cat=video]) {
opacity: 0.15;
transform: scale(0.94);
pointer-events: none;
}
@media (prefers-reduced-motion: reduce) {
.ft-indicator, .ft-tile {
transition: none !important;
}
}var frame = document.querySelector('.ft-frame');
if (frame.classList.contains('is-demo')) {
var radios = document.querySelectorAll('.ft-radio'), i = 0;
var iv = setInterval(function () { i = (i + 1) % radios.length; radios[i].checked = true; }, 700);
radios.forEach(function (r) {
r.addEventListener('change', function () { frame.classList.remove('is-demo'); clearInterval(iv); });
});
}import { useState } from "react";
import styles from "./FilterTabsHas.module.scss";
export interface FilterTabsHasProps {
duration?: string;
easing?: string;
color?: string;
}
const TABS = ["All", "Photo", "Video"] as const;
const TILES: { cat: "photo" | "video" }[] = [
{ cat: "photo" }, { cat: "video" }, { cat: "photo" },
{ cat: "video" }, { cat: "photo" }, { cat: "video" },
];
export default function FilterTabsHas({
duration = "300ms",
easing = "cubic-bezier(.2, 1.4, .4, 1)",
color = "#2f6df6",
}: FilterTabsHasProps) {
const [active, setActive] = useState(0);
const filterCat = active === 1 ? "photo" : active === 2 ? "video" : null;
return (
<div className={styles.frame}>
<div className={styles.tabs}>
<span
className={styles.indicator}
style={{ transform: `translateX(${active * 64}px)`, transitionDuration: duration, transitionTimingFunction: easing, background: color }}
/>
{TABS.map((label, i) => (
<button key={label} type="button" className={styles.tab} onClick={() => setActive(i)}>{label}</button>
))}
</div>
<div className={styles.gallery}>
{TILES.map((t, i) => {
const dim = filterCat !== null && t.cat !== filterCat;
return (
<div
key={i}
className={`${styles.tile} ${styles["tile-" + t.cat]}`}
style={{ opacity: dim ? 0.15 : 1, transform: dim ? "scale(.94)" : "scale(1)", transitionDuration: duration, transitionTimingFunction: easing }}
/>
);
})}
</div>
</div>
);
}09 :has 기반 필터 탭 — 측정 누적면적 24.351% · 움직인 프레임 13/23GODRICH 원작 · zip 에 SCSS·React 포함 · CSS 이미지 슬라이드 애니메이션 9종
이 데모가 속한 글
CSS 이미지 슬라이드 애니메이션 9종사진 위에 마우스를 올리면 커튼처럼 열리거나 원이 점점 커지며 드러나는 걸 본 적 있으신가요? 이런 CSS 이미지 슬라이드 애니메이션을 한 줄 복붙으로 쓸 수 있게 아홉 가지로 모았고, 그중 하나는 자바스크립트 없이 이 글의 데모 전부 보기


