CSS Parent/Ancestor Selector [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-11-26 22:58:40

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.

That's what jQuery is for :-)

In CSS there is an :empty selector that allows you to match empty elements, you can negate the effect with :not selector.

div:not(:empty) {
    // your styles here
}

However I'm not sure if all browsers support this.

MikeD
div:not(:empty) {
    margin:0;
}

is NOT recognized by http://jigsaw.w3.org/css-validator/ as CSS2

it's the purpose of CSS to "cascade" down from the more containing to the more specific elements. I guess it's possible for you to "reverse your logic", like in

div.myclass   { /* format parent */ }
div.myclass * { /* neutralize formats in descendants */}
div.myclass img { /* more specific formats for img children */ }

good luck Mike

:empty pseudoclass supported by Firefox, but is not compatible with IE.

But a very simple jQuery workaround for IE is at http://www.webmasterworld.com/css/3944510.htm . Saved my bacon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!