选择具有某个类的元素,如果它是一个&只有“可见”其父母的孩子? [英] Selector for an element with certain class, if it is the one & only "visible" child of its parent?

查看:83
本文介绍了选择具有某个类的元素,如果它是一个&只有“可见”其父母的孩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就在今天,我问了:



但是如果我们需要选择具有类的元素,如果它是一个&只有可见的父级子项?我知道使用jQuery可以轻松完成,但我正在寻找纯粹的CSS解决方案(适用于所有主流浏览器)。我可以写这些元素的CSS选择器表达式吗?

无法确定对象是否可见,所以这是不可能的。请注意,jQuery也只能确定某个对象是否为可见,因此对于可见的某个定义。



这里有一个< a href =http://jsfiddle.net/k47mc/ =nofollow>举例失败

 <身体GT; 
< div style =position:absolute; top:-100px> Am I visible?< / div>
< / body>

这是另一个。哎呀,甚至能见度:隐藏 被视为可见。有很多创造性的方法可以让某些人不可见,所以这个词在我们开始谈论技术之前需要一个严格的定义。

Just today I asked

Selector for an element with certain class, if it is the one & only child of its parent?

but what about if we need to select elements with a class , if it is the one & only "visible" child of its parent? I know it can be easily done using jQuery but I'm looking for a pure CSS solution(that works across all major browsers). Can I write CSS selector expression for such elements ?

解决方案

There is no way to determine if an object is "visible" with CSS, so it's not possible. Note that jQuery is also only capable of determining if an object is "visible" for a certain definition of "visible".

Here's an example where it fails:

<body>
    <div style="position:absolute; top: -100px">Am I visible?</div>
</body>

Here is another. Heck, even visibility: hidden is considered visible. There are lots of creative ways to make something "not visible" to a human, so that term needs a rigorous definition before we are able to start talking tech.

这篇关于选择具有某个类的元素,如果它是一个&amp;只有“可见”其父母的孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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