CSS父/祖选择器 [英] CSS Parent/Ancestor Selector

查看:136
本文介绍了CSS父/祖选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

是否有一个CSS父选择器?

知道这是一个在黑暗中的镜头,但有没有办法,使用CSS只,CSS2,没有jquery,没有javascript,选择和样式元素的祖先?我已经通过选择器,但发布这种情况下,如果我错过了一些或有一个聪明的解决方法。

I know this is a shot in the dark, but is there a way, using css only, CSS2, no jquery, no javascript, to select and style an element's ancestor? I've gone through the selectors but am posting this in case I missed something or there is a clever workaround.

例如,我有一个表与classnametest 嵌套在一个div。是否有某种类型:

For example, say I have a table with classname "test" nested inside a div. Is there some sort of:

<div>
    <table class="test">
    </table>
</div>



div (with child) .test
{
     /*styling, for div, not .test ...*/
}


推荐答案

在CSS2或CSS3中没有父选择器。并且可能永远不会,实际上,因为CSS的整个级联部分不会是漂亮的处理一旦你开始做父选择器。

There is no such thing as parent selector in CSS2 or CSS3. And there may never be, actually, because the whole "Cascading" part of CSS is not going to be pretty to deal with once you start doing parent selectors.

这是jQuery的用途: - )

That's what jQuery is for :-)

这篇关于CSS父/祖选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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