Is parent selector available in css4?

Here is a fiddle , and I have 2 divs one is the external field and the other is the innerBox , when I click the innerBox I need to change the property of the outer box .

As in css3, this is not possible, so is it still available in css4?

+7
html css-selectors css3
source share
2 answers

There may not be such a thing as CSS4, but there is such a thing as Level 4 Selectors. This is an incomplete specification for the next generation of selectors and includes a parent selector in the specification. Or, more precisely, the subject selector.

The specification document is here: http://dev.w3.org/csswg/selectors/

But note that this is the URL dev , and the specification is still very important to work with.

In real code, an object selector might look like this:

 div > !.foo > span 

This will select an element with class foo , which is a child of the div , and has a span in it as a child of the element.

However, as I said, this is not a complete specification (indeed, the syntax of the object selector has changed more than once during the process and may still be subject to further changes at any time). It is also not yet implemented in any of the browsers, and there is no expectation that it will be either in the near future.

In addition, even if / when selector level 4 is implemented in browsers, the specification explicitly states that some selectors may be excluded from the implementation for performance reasons (they distinguish between "fast" selectors and a "complete" set of selectors). The theme selector is one of the following: if the specification remains as it is, then browsers will not have any compulsion to add it to CSS. In this case, they could add it to Javascript, i.e. for methods like document.querySelector() , but not for CSS itself. This will not help you in any way, since in any case you can already find the parent element using javascript. (For more on this, see Section 2.1 in the specification above).

So the short answer is: No, this is not possible. This is possible in the future, but it will not help you now, and even in the future, show stops may be agreed.

(You can also read this article , which is a more user-friendly document than the actual specification. But you will notice that the topic selector syntax has changed since this article was written)

+10
source share

As Liam pointed out, CSS4 does not exist.

Forget the parent selector as it contains many new problems.

There is a reason why she is not there.

With parent selectors, it becomes extremely easy to accidentally fragment a document. People can and will abuse this selector. Supporting this gives people a whole rope to hang themselves with

and

What I described is technically impossible. In fact, quite the opposite. It just means that we will have to deal with the performance implications of using such a function.

But you can easily do this with js or even use jquery. Its as simple as calling $('a').parent(); in jquery to get parent <a> tags.

A source

Edit:

Heads Up! . Level 4 selectors implement this function. Thanks TylerH for this.

+2
source share

All Articles