Pseudo class selector focus within, which indicates that an element gets the focus, or the descendant of that element gets the focus. Focus, it or its offspring get the focus.
This means that it, or its offspring, gets the focus and can trigger it:focus-within
。
Code example:
//html
<div class="container" tabindex="0">
<label for="text">Enter text</label>
<input id="text" type="text" />
</div>
//css
.container:focus-within {
background-color: #aaa;
}
Here is the demo Animation:
When the input element is selected, the style changes
It or its offspring gain focus, which makes the perceptual focus area larger, so the most common use is to use:focus-within
Sensing user operation focus area, highlight reminder.