- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
在处理当用户将鼠标悬停在父菜单项上时(展开)折叠的子菜单时,我遇到了以下问题。考虑以下标记(在 JSFiddle 下方或上方)。
ul {
max-height: 0;
overflow: hidden;
margin: 10px;
padding: 0;
border: 10px solid #bada55;
list-style-type: none;
transition: border-color .4s;
}
ul:hover {
max-height: 100px;
border-color: #de2d26;
}
ul > li {
padding: 10px;
pointer-events: auto;
}
.ignorant {
pointer-events: none;
}
.offset {
position: relative; /* This is the culprit! */
}
<ul class="ignorant">
<li>I am ignorant of your pointer.
If you see me, something went wrong!</li>
</ul>
<ul>
<li>I am not. Hover me!</li>
</ul>
<ul class="ignorant offset">
<li>I should be ignorant of your pointer.
If you see me, something went wrong!</li>
</ul>
设置。 我们这里有三个列表,其中的内容是隐藏的,因为 max-height
列表的设置为 0。边框仍然显示,这是预期的行为:元素的高度指令 by default仅适用于元素的内容。
我们通过将 max-height
设置为足够大的值,在悬停列表时显示内容。
现在,我想让列表仅在内容悬停时可见,而不是边框。我相信,这应该可以使用 pointer-events
来实现。如上所示。忽略边框上的事件并在列表中的元素上重新启用它们。
问题。到目前为止,一切顺利,这在 Firefox 中运行良好,主要是在 Chrome 中。即,当我定位容器时 relative
, 可以触发 Chrome 中内容的悬停。
Firefox 仍然像我预期的那样工作,没有触发悬停。当没有边框时,在 Chrome 中也不再可能触发悬停。
问题。这是 Chrome 中的错误吗?还是没有明确规定应该如何处理,因此未定义行为?我会对以下任何一项感兴趣:
1. 解释我做错了什么,以及为什么;
2. 解释为什么不同的浏览器在这种情况下可以有不同的行为;
3. 简要解释为什么这是一个错误。在这种情况下,我很乐意报告一个。
目前,这是通过
测试的• Firefox 52.0.1(64 位 Linux N);
• Firefox 52.0.2(64 位 Windows N);
• Internet Explorer 11.0.9600.17031(64 位 Windows N);
• Chrome 57.0.2987.133(64 位 Linux S、64 位 Windows S);
• Chromium 57.0.2987.98(64 位 Linux S)。
S 表示显示,N 表示悬停时不显示,当使用相对定位时。
感谢 BoltClock通过他们的建设性意见使这个问题变得更好。
最佳答案
悬停事件在所有浏览器上以相同的方式冒泡,this example 证明了这一点.
ul {
max-height: 0;
/* overflow: hidden; */
margin: 10px;
padding: 0;
border: 10px solid #bada55;
list-style-type: none;
transition: border-color .4s;
}
ul:hover {
max-height: 100px;
border-color: #de2d26;
}
ul > li {
padding: 10px;
pointer-events: auto;
position: relative;
top: 100px;
background: yellow;
}
.ignorant {
pointer-events: none;
}
.offset {
position: relative;
}
<ul class="ignorant offset">
<li>Hover me! Testing :hover across browsers...</li>
</ul>
我得出的结论:
position: relative
或 display: inline
时不会发生。仅当鼠标悬停在子模型覆盖与其父模型相同像素的区域上方时,才会触发悬停。可以在屏幕上的蓝色矩形正上方看到该区域。不要说它是浅绿色什么的,我只是一个简单的程序员,我对颜色一无所知。
Chrome 隐藏子元素是因为其父元素的 overflow: hidden
属性是预期的行为。出乎意料的是 child 的事件框(如果我可以这样称呼的话)仍然“可见”并且悬停在它的 parent 的边界上,就像 overflow: visible
一样。
奇怪的是,正如我之前所说,当 child 有 position: relative
或 display
而不是 block
时,这并没有发生.
根据 W3C :
Once a box has been laid out according to the normal flow or floated, it may be shifted relative to this position. This is called relative positioning. Offsetting a box (B1) in this way has no effect on the box (B2) that follows: B2 is given a position as if B1 were not offset and B2 is not re-positioned after B1's offset is applied.
据我了解,这意味着 position: relative
应该对框没有影响。它已经证明这是一个 Chrome 错误。
至于指针事件。 MDN states :
Note that preventing an element from being the target of mouse events by using pointer-events does not necessarily mean that mouse event listeners on that element cannot or will not be triggered. If one of the element's children has pointer-events explicitly set to allow that child to be the target of mouse events, then any events targeting that child will pass through the parent as the event travels along the parent chain, and trigger event listeners on the parent as appropriate. Of course any mouse activity at a point on the screen that is covered by the parent but not by the child will not be caught by either the child or the parent (it will go "through" the parent and target whatever is underneath).
这意味着 Chrome 不会在其父项的顶部显示子项的事件框,但实际上在其下方。只是事件通过父元素并击中它的子元素。不过,overflow: hidden
不应该发生这种情况。
关于css - 悬停零高度元素 : browser bug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43183249/
在 Firefox 扩展的 Javascript 中,您可以调用 gBrowser.getBrowserForTab但是没有gBrowser.getTabForBrowser .所以我写了自己的并且它
在问这个可能含糊不清的问题之前,我搜索了 SO,发现许多对“现代浏览器”的引用,但没有定义。由于这是一个被广泛使用和引用的术语,令我惊讶的是我在 Internet 上找不到定义甚至描述。 那么,在 2
更新:老问题仅适用于 IE11 预览版;浏览器模式在 IE11 最终版本中回归。但有一个问题:它几乎没有用,因为它不模拟条件注释。例如,如果您使用它们在旧版 IE 中启用 HTML5 支持,您将无法再
我的移动页面和短信有问题:链接。该页面主要由基于 Android 和 iOS 的智能手机通过 QR 扫描应用程序访问。 特别是在 iPhone 上,有一些带有集成浏览器的 QR 应用程序(webkit
我想使用 CustomTabsIntent。但是我没有找到androidx的customTabs路径和版本。 最后我得到了这个:androidx.browser:browser:1.0.0 我想知道正
我想将来自不同域(支付提供商)的 ssl 安全页面加载到 iframe 中。据我所知,一些(或全部?)浏览器会在页面的某些部分受到保护而其他部分不安全时警告用户。 这是真的吗? 如果是这样,如果主站点
在 Protractor 中,有 browser.pause() function : Beta (unstable) pause function for debugging webdriver t
我可以使用以下方法检索浏览器日志 browser.manage().logs().get('browser').then(function(browserLog) { logger.info('
当使用 protractor 时,全局变量 browser 似乎具有 browser.driver 的所有功能。 我特地问这个是因为我不确定是使用 browser.wait 还是 browser.dr
面对 Protractor 的计时问题。有时我的 Protractor 测试用例会因网络或性能问题而失败。我已经解决了 browser.sleep() 的现有问题。后来知道了browser.wait(
我仍然无法找到解决此问题的方法。我们有一个启动浏览器窗口的应用程序,但我们使用的底层第三方插件尚不支持 IE9。我知道我可以通过点击 F12 并选择它来切换到 IE8 的浏览器模式。 有没有办法在命令
在 Protractor 脚本中,我总是遇到超时问题,即使我设置了很大的 time out jasmine interval、allscripttimeout...在某些地方,我不得不等到元素出现,比
我正在运行一个 Angular 应用程序,并且在 Protractor 上测试时尝试获取当前 URL。使用哪一个? browser.driver.getCurrentUrl() 或 browser.g
“所有浏览器兼容”和“跨浏览器兼容”有什么区别? “交叉”是什么意思,是指不同的操作系统吗? 如果任何网站在 IE 7、8 FF 3+、Safari 3+ 的桌面版本上运行良好,我们可以说它是跨浏
不明白浏览器同步中的错误阅读文档,其中 gulp 4 真的没有写任何关于它的内容。在 gulp 4 的文档中也没有理解(异步)。如何解决这个问题。谢谢。 bla bla bla bla bla bla
我正在尝试在 ASP.Net C# 代码隐藏中执行“如果浏览器是 IE 且版本低于 9”。 但是,在 chrome 中,以下行: if (Request.Browser.Browser == "IE"
我第一次玩 watir,使用 this site作为指导。我在一个简单的程序(如下)中遇到错误 - 它在第一个非要求行失败,如图所示。 如果我没有运行下面显示的内容,而是删除了该行,它会打开一个空的
下面的 if 条件我认为它是说 - 如果浏览器是 IE 并且 IE 浏览器版本高于 9,但我没有 IE 9 来测试它,所以很难知道正确的输出,这也是不是 100% 的我想要的 bcos 默认情况下该脚
我通过 Pingdom 测试了我的网站并得到了这个: 我进行了搜索,但找不到解决方案。有谁知道我怎样才能得到这个14到100? 最佳答案 不是一个完整的解决方案,但您可以通过将两个请求合并为一个来改善
是否可以禁用浏览器/窗口之间的 HTML5 拖放功能? 我正在使用具有 native HTML5 拖放功能的 Angular2 应用程序,并希望防止用户将其拖动到浏览器窗口之外并防止将可拖动对象拖放到
我是一名优秀的程序员,十分优秀!