简体   繁体   English

Android Webkit:绝对定位的元素不尊重z-index

[英]Android Webkit: Absolutely positioned elements don't respect z-index

Nasty little bug, this one. 令人讨厌的小虫子,这个。

As illustrated in Android ticket 6721 , the Android browser seems to not respect z-index when absolutely positioned elements are laid over the top of <a> or <input> tags. Android票证6721所示 ,当绝对定位的元素放在<a><input>标记的顶部时,Android浏览器似乎不尊重z-index。 I am desperate for any sort of workaround. 我迫切需要任何解决方法。 Has anybody conquered this one before? 有人曾经征服过这个吗?

Thanks in advance! 提前致谢!

This problem is probably related to controls and their being special for the browser. 此问题可能与控件及其对浏览器的特殊关系有关。 While looking at your problem (in chromium) I found a related problem that when you press the tab key you will still be able to focus the input elements. 在查看您的问题(铬)时,我发现了一个相关的问题,当您按Tab键时,您仍然可以聚焦输入元素。 You probably don't want this either (regardless of bleedthrough). 你可能也不想要这个(不管渗透)。 The solution is surprisingly simple, you write your script to add the disabled attribute to all input/button/etc. 解决方案非常简单,您编写脚本以将disabled属性添加到所有输入/按钮/等。 elements that are overlayed. 重叠的元素。 A disabled input will not be able to receive focus (by keyboard or otherwise), and clicking it should be impossible. 禁用的输入将无法通过键盘或其他方式获得焦点,并且无法单击它。

As this also disables silly keyboard circumnavigation it is not even a workaround, but a better design that also works with keyboard based navigation as expected. 由于这也禁用了愚蠢的键盘环绕,它甚至不是一种解决方法,而是一种更好的设计,也可以按预期使用基于键盘的导航。

To answer the question properly it's important to read the bug page. 要正确回答这个问题,请务必阅读错误页面。 The problem is not about visibility of the input below, but its "clickability". 问题不在于下面输入的可见性,而在于它的“可点击性”。

I can't test it, but these are possible workarounds: 我无法测试它,但这些是可能的解决方法:

0 Forget absolute positioning and just put two divs there and toggle visibility. 0忘记绝对定位,只需在其中放置两个div并切换可见性。

If this doesn't satisfy You... 如果这不满足你......

1 try setting CSS position to absolute or relative for all a and input tags (Yup, this might force You to rewrite CSS to keep the layout, but isn't it worth it?) 1尝试将CS​​S位置设置为所有ainput标签的绝对或相对(Yup,这可能会强制您重写CSS以保持布局,但是不值得吗?)

2 make a <a> -tag container: 2创建一个<a> -tag容器:

 <div style="z-index:100 etc."><a style="width: 100%; height:100%; z-index:101">
     stuff here
 </a></div>

This will need some more CSS to make the content look ok. 这将需要更多的CSS来使内容看起来不错。 But I expect something like this would solve the problem. 但我希望这样的事情可以解决问题。

if 1 and 2 aren't helping try them both at once ;) 如果1和2都没有帮助去尝试一下在一次;)

3 if it still happens You might want to check in details what happens when You click. 3,如果它仍然发生您可能想要查看详细信息,单击时会发生什么。 Bind click and mousedown events to: link on top , container on top , input in the bottom and log them. 将click和mousedown事件绑定到: link on top container on topinput in the bottom并记录它们。 If You get any of those events for the top link You can try and stop the bubbling at some moment or prevent the event on the input in the bottom. 如果您获得顶部链接的任何事件您可以尝试在某个时刻停止冒泡或阻止底部输入的事件。

This would be difficult, but I can help a bit. 这很难,但我可以帮助一下。 jQuery would be quite necessary. jQuery非常必要。

将此添加到创建问题的每个元素的CSS:

 -webkit-backface-visibility: hidden;

Past fixes for this issue for IE include, but are probably not limited to the following list. IE的此问题的过去修复包括,但可能不限于以下列表。 These may help solve the problem in Android for you. 这些可能有助于您解决Android中的问题。

  1. Put an iframe behind the absolute content. 将iframe放在绝对内容后面。 The iframe may obscure those elements for you iframe可能会为您隐藏这些元素

  2. When you display your absolute content, hide all of the problem elements with JavaScript 显示绝对内容时,使用JavaScript隐藏所有问题元素

  3. Define the div's in the opposite order 以相反的顺序定义div

Point number 1 is deemed the most reliable fix for IE, but may not be the nicest fix for you. 点号1被认为是IE最可靠的解决方案,但可能不是最好的解决方案。

Simulate INPUT and A with DIVs. 使用DIV模拟INPUT和A.

[PSEUDO JQUERY CODE]

<div href="http://google.com" rel="a">Link</div>

<div class="field">
    <div></div>
    <input type="text" style="display: none" />
</div>

<script>
    $('div[rel=a]).click(function() {
        location.href = $(this).attr('href');
    });
    $('.field > div').click(function() {
        $(this).hide();
        $('.field > input').show();
    });
    $('.field > input').blur(function() {
        $(this).hide();
        $('.field > div').html($(this).val()).show();
    });
</script>

如果你想解决这个问题,首先你必须将z-index添加到父包装器并明确地将z-index添加到其他元素,解决方案是所有元素都将正确地理解z-index属性的零点

IE has this same problem and the solution there is to make sure that every element that is involved in the positioning and even their containers have a z-index applied to them. IE有同样的问题,解决方案是确保定位中涉及的每个元素甚至它们的容器都应用了z-index。 Basically if you add a z-index to 1 element in the dom then IE gets understands its z position but doesn't understand its z position relative to what its next to and/or over. 基本上,如果你在dom中向1个元素添加一个z-index,那么IE就会理解它的z位置,但是不了解它的z位置相对于它的下一个和/或哪个。

container - z-index 0 容器 - z-index 0
child (on top container) - z-index 1 孩子(在顶部容器上) - z-index 1
child 2 (above all) - z-index 999 孩子2(最重要的) - z-index 999

Of course this is all based on stupid IE but its worth a try in android also. 当然这都是基于愚蠢的IE,但它也值得一试。


Second Try :) 第二次尝试:)

I am not familiar with the android browser at all, but I hope to maybe lead you down a path to solve your issue. 我根本不熟悉android浏览器,但我希望可能会引导你走上解决问题的道路。 Superfish is a javascript menu that has implemented a solution for z-index menu items when they drop down over select boxes in browsers. Superfish是一个javascript菜单,当它们下拉到浏览器中的选择框时,它已经实现了z-index菜单项的解决方案。 BgIframe is the js that they use to achieve this. BgIframe是他们用来实现这一目标的js。 Your answer may lie there, hopefully. 希望你的回答可能就在那里。

http://users.tpg.com.au/j_birch/plugins/superfish/#sample2 http://users.tpg.com.au/j_birch/plugins/superfish/#sample2

将html放在div中并使用javascript设置display:none,这样底层内容就消失了,而不是可点击和模态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM