gpt4 book ai didi

css - 使用 CSS 更改带有嵌套输入字段的字段集的背景颜色

转载 作者:行者123 更新时间:2023-11-28 01:35:07 26 4
gpt4 key购买 nike

我正在使用这个解决方案: Is it possible to change a fieldset's background-color on input:focus?

... 当用户在表单中移动时更改字段集的背景。在基本层面上,这很好用。在更高级的级别上,我无法在嵌套在条件 div 内的输入字段上进行这项工作。换句话说,在他的示例中,输入不再是 div 的兄弟。

给你一个视觉效果,这是可行的:

<fieldset>
<input>
<div></div>
</fieldset>

但这不是:

<fieldset> 
<div class="conditional">
<input>
</div>
<div></div>
</fieldset>

最佳答案

实际上,您现在可以通过

影响焦点输入的父级
:focus-within

The :focus-within CSS pseudo-class represents an element that has received focus or contains an element that has received focus. In other words, it represents an element that is itself matched by the :focus pseudo-class or has a descendant that is matched by :focus. (This includes descendants in shadow trees.)

MDN

fieldset:focus-within {
background: red;
}
<fieldset>
<input>
</fieldset>

关于css - 使用 CSS 更改带有嵌套输入字段的字段集的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50728928/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com