且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

影响的父元素:focus'd元素(纯CSS + HTML首选)

更新时间:2023-12-01 23:42:16

不幸的是,css不支持父选择器。(

因此,唯一的方法是使用类似于 jQuery parent method



更新:
CSS Selectors Level 4将支持父选择器! http://www.w3.org/TR/selectors4/#subject p>

How can I change the background of a parent <div> when an <input> or <a> is :focus'd (or any other dynamic pseudo-class?

Eg

<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>

Unfortunately css doesn't support parent selectors. :(
So the only way to do it is to use javascript like the jQuery parent method.

Update: CSS Selectors Level 4 will support parent selectors! http://www.w3.org/TR/selectors4/#subject