Affecting parent element of :focus#39;d element (pure CSS+HTML preferred)(影响 :focusd 元素的父元素(首选纯 CSS+HTML))
问题描述
当 <input>
或 <a>
为时,如何更改父 <div>
的背景:聚焦(或任何其他动态伪类?
How can I change the background of a parent <div>
when an <input>
or <a>
is :focus'd (or any other dynamic pseudo-class?
例如
<div id="formspace">
<form>
<label for="question">
How do I select #formspace for the case when a child is active?</label>
<input type="text" id="question" name="answer"/></form></div>
推荐答案
很遗憾,css 不支持父选择器.:(
所以唯一的方法就是使用像 jQuery 父方法这样的 javascript.
Unfortunately css doesn't support parent selectors. :(
So the only way to do it is to use javascript like the jQuery parent method.
更新:CSS 选择器 Level 4 将支持父选择器!http://www.w3.org/TR/selectors4/#subject
Update: CSS Selectors Level 4 will support parent selectors! http://www.w3.org/TR/selectors4/#subject
这篇关于影响 :focus'd 元素的父元素(首选纯 CSS+HTML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:影响 :focus'd 元素的父元素(首选纯 CSS+HTML)


基础教程推荐
- 直接将值设置为滑块 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01