父选择器是否在css4中可用? [英] Is parent selector available in css4?

查看:163
本文介绍了父选择器是否在css4中可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是小提琴,我有2的div一是外包装盒,另一个是内盒个数,在点击内盒个数我需要改变外框的属性

Here is fiddle and I have 2 divs one is outer box and another is the innerBox, On clicking innerBox I need to change the property of the outer box.

作为CSS3其不可能的,所以什么事情可以在CSS4?

As of css3 its not possible, so is anything available in css4?

推荐答案

可能没有CSS4这样的东西,但有一个东西,如选择器级别4。这是下一代选择器的未完成规范,并且 在规范中包含父选择器。 。或者更准确地说,是主题选择

There may not be such a thing as CSS4, but there is such a thing as "Selectors Level 4". This is an unfinished spec for the next generation of selectors, and does include a parent selector in the spec. Or more accurately, a "subject" selector.

该规范文件是在这里:的 http://dev.w3.org/csswg/selectors/

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

但请注意,这是一个 dev

But note that it is a dev URL, and the spec is still very much a work-in-progress.

在实际代码中,主题选择器看起来可能是这样的:

In real code, the subject selector might look like this:

div > !.foo > span

这将选择与类的元素,它是 div 的子级,并且在其中有 span 作为子级。

This would select an element with the class foo, that is a child of a div, and has a span within it as a child.

然而,正如我所说,这不是一个完成的规范(事实上,主题选择器的语法在过程中已经改变了不止一次,并且可能仍然会进一步改变任何时候)。

However as I said, this is not a finished spec (indeed, the syntax for the subject selector has changed more than once during the process, and may still be subject to further change at any time). It is also not implemented yet in any of the browsers, and there is no expectation of it being so either any time soon.

此外,即使/当选择器级别4在浏览器中实现,规范明确指出,出于性能原因(它们区分快速选择器和完整选择器集合),一些选择器可以被忽略。主题选择器是以下之一:如果规范保持原样,则浏览器不会强制将其添加到CSS。在这种情况下,他们可能会将它添加到Javascript,即 document.querySelector(),但不是CSS本身。这不会真的帮助你在任何方面,因为它已经可以通过JavaScript找到一个父元素。 (参见上面链接的2.1节中的更多内容)。

In addition, even if/when Selectors Level 4 is implemented in the browsers, the spec explicitly states that some selectors can be left out of the implementation for performance reasons (they differentiate between 'fast' selectors and the 'complete' set of selectors). The subject selector is one of these: If the spec remains as is, then browsers would have no compulsion to add it to CSS. In this case, they would maybe add it to Javascript, ie for methods like document.querySelector() but not to CSS itself. This wouldn't really help you in any way, since it's already possible to find a parent element via javascript anyway. (See section 2.1 in the spec linked above for more on this).

所以简短的答案是:不,这是不可能的。这可能是在未来,但这不会帮助你,即使在将来也可能有显示停止的警告。

So the short answer is: No, it isn't possible. It may be possible in the future, but that doesn't help you now, and even in the future there may be show-stopping caveats.

(你可能也喜欢阅读本文,这是一个更加最终用户友好的但是你会注意到,自从写这篇文章以来,主题选择器语法已经改变)

(you may also like to read this article which is a more end-user-friendly document than the actual spec. But you'll note that the subject selector syntax has changed since this article was written)

这篇关于父选择器是否在css4中可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆