<form>
    <fieldset>
        <legend>이름을 입력하세요.</legend>
        <label for="user-name">Usrname</label>
        <input type="text" id="user-name" placeholder="이름 입력...">
    </fieldset>
</form>
fieldset {
    padding: 1em;
}
fieldset:focus-within { /* 자기 또는 자손 요소가 포커스되었을 동안 선택됨 */
    background-color: yellow;
}
실제 적용된 모습 - 시도해 보세요! 이름을 입력하기 위해 <input> 태그에 포커스하면 조상 요소인 <fieldset>에 설정한 fieldset:focus-within 스타일인 노란 배경색이 적용됩니다.
:focus-within {
    /* ... */
}
<form>
    <fieldset>
        <legend>연락처 정보</legend>
        <label for="email">이메일</label>
        <input type="email" id="email" placeholder="이메일을 입력하세요">
    </fieldset>
</form>
fieldset {
    padding: 1em;
    border: 2px solid gray;
    transition: border-color 0.3s ease;
}
fieldset:focus-within {
    border-color: blue;
    background-color: #e6f0ff;
}
실제 적용된 모습
<div class="card" tabindex="0">
    <h3>제품 제목</h3>
    <p>이 제품에 대한 간단한 설명입니다.</p>
    <button>자세히 보기</button>
</div>
<div class="card" tabindex="0">
    <h3>또 다른 제품</h3>
    <p>다른 제품에 대한 간단한 설명입니다.</p>
    <button>자세히 보기</button>
</div>
.card {
    border: 1px solid #ccc;
    padding: 1em;
    margin: 1em 0;
    border-radius: 4px;
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
    outline: none;
}
.card:focus-within {
    border-color: #007acc;
    box-shadow: 0 0 10px #007acc;
}
실제 적용된 모습