简体   繁体   English

如果容器上有溢出滚动,则Z-index在表内不起作用

[英]Z-index not working inside a table if there is an overflow-scroll on container

I'm having a problem positioning an absolute div outside a table, I'm not a big fan of table layout but I found an existing project with a table layout. 我在将一个绝对div放在桌子外面时遇到了问题,我不是桌面布局的忠实粉丝,但我找到了一个带有桌面布局的现有项目。 The code is as follows 代码如下

<td colspan="2" align="right" style="padding-top:3px; padding-right:15px; padding-bottom:15px;" width="600px">
    <table cellpadding="0" cellspacing="0" border="0">
        <tr><td height="37px" width="600px" style="background-image:url('P--IMG--P/welcomepanel/header.png'); background-repeat:no-repeat; background-position:bottom left;"><span class="heading" id="I--heading_text--I" style="padding-top:3px;"></span></td></tr>
        <tr>
            <td align='left' valign='middle' width="600px" height="522px" style="background-image:url('P--IMG--P/welcomepanel/middelblock_repeat.png'); background-repeat: repeat-y; padding-top:0px">
                <div height="500px" width="580px" style="width:600px; text-align:left; height:500px; overflow-y:scroll; overflow-x:none;">
                    [--C--comp--C--]
                </div>
            </td>
        </tr>
        <tr><td><img src="P--IMG--P/welcomepanel/middelblock_roundcorners.png"/></td></tr>
    </table>
</td>

Where [--C--comp--C--] is the replacement string for an fckEditor that contains an image inside a div, I have set that div's z-index to 10 but it doesn't want to go out of the table.. and its position absolute. 其中[--C--comp--C--]是包含div内部图像的fckEditor的替换字符串,我将div的z-index设置为10,但它不想离开table ..和它的位置绝对。

Please let me know what I might be doing wrong. 请让我知道我可能做错了什么。

I've realised that the problem comes with the overflow-scroll on the td container, if you remove the overflow-y:scroll it works fine, but the problem is that I need to have that overflow since there is a lot of content inside that td. 我已经意识到问题来自td容器上的溢出滚动,如果你删除overflow-y:scroll它工作正常,但问题是我需要有溢出,因为里面有很多内容那个td。 I don't know what to do now. 我现在不知道该怎么办。 :(..someone please help a brother out! :( ..有人请帮助一个兄弟!

在此输入图像描述

I need the small map to be outside the table and the big map to remain inside the table, it shows the small image when you hover on the big map using Jquery to zoom, which is loaded on the fckeditor. 我需要将小地图放在桌子外面并将大地图留在桌子内,当你使用Jquery悬停在大地图上时,它会显示小图像,这是在fckeditor上加载的。 I hope this helps.. 我希望这有帮助..

For z-index to work correctly, every element that has a z-index property must also have any position set ( egposition:relative ). 为了使z-index正常工作,具有z-index属性的每个元素也必须具有任何位置集(egposition:relative)。 Also, I'd assign the table a position and z-index for the two to compare. 另外,我会为表分配一个位置和z-index来进行比较。

In saying that you want to absolutely positioned element "to go out of the table", do you mean that you want it to be positioned outside the table, not based on the table's location? 在说你想要绝对定位元素“走出桌面”时,你的意思是你希望它被放置在桌子外面,而不是基于桌子的位置吗? Or do you mean you want it located inside the table, but not clipped to the table's borders or overlapped with other content? 或者您的意思是您希望它位于表格内,但不会剪裁到表格的边框或与其他内容重叠?

If it's the former, I'd suggest moving the absolutely-positioned DIV elsewhere in the code. 如果它是前者,我建议将绝对定位的DIV移动到代码中的其他位置。 Why put it inside the table if it's not going to be shown there? 如果它不会在那里显示,为什么要把它放在桌子里? It just makes the stacking context and overflow properties harder to work around. 它只是使堆叠上下文和溢出属性更难解决。

If it's the latter, you might want to adjust or remove the overflow-x and overflow-y properties on the div that contains your absolutely positioned element. 如果是后者,您可能需要调整或删除包含绝对定位元素的div上的overflow-xoverflow-y属性。 It's conceivable that the browser would still apply the overflow clipping rules to child elements, even if they're absolutely positioned. 可以想象,浏览器仍会将溢出剪辑规则应用于子元素,即使它们是绝对定位的。

Also, keep in mind that z-index is only meant to affect the stacking order of sibling elements. 另外,请记住, z-index仅用于影响同级元素的堆叠顺序。 Elements that are on the same level of the tree, in other words other elements inside your 500px-height div, will be stacked according to their z-order, but parent and child nodes play by different rules. 位于树的同一级别的元素,换句话说,500px-height div中的其他元素将根据其z顺序堆叠,但父节点和子节点按不同的规则播放。

If this answer doesn't help, then maybe I'm misunderstanding what you want to do. 如果这个答案没有帮助,那么也许我误解了你想做什么。 Can you post a picture of how it's behaving and describe how you'd like it to behave? 你能发一张它的表现如何并描述你喜欢它的表现吗?

Edit in reply to picture being posted: 编辑回复发布的图片:

I think what you want to do in this case is to get the small map outside of the scroll DIV somehow. 我想在这种情况下你想做的是以某种方式在滚动DIV之外获取小地图。 Can you change this... 你能改变一下......

<div height="500px" width="580px" style="width:600px; text-align:left; height:500px; overflow-y:scroll; overflow-x:none;">
    [--C--comp--C--]
</div>

...to something like this? ......这样的事情?

[--C--compSmallMap--C--] <!-- Small map code goes here -->
<div height="500px" width="580px" style="width:600px; text-align:left; height:500px; overflow-y:scroll; overflow-x:none;">
    [--C--compBigMap--C--] <!-- Big map code goes here -->
</div>

If not, could you change the code that's getting inserted so that it creates the small map at a higher level in the code? 如果没有,您是否可以更改插入的代码,以便在代码中的更高级别创建小地图? For example, you can add elements to the root node using document.getElementsByTagName("body")[0].appendChild(element); 例如,您可以使用document.getElementsByTagName("body")[0].appendChild(element);将元素添加到根节点document.getElementsByTagName("body")[0].appendChild(element); (there might be a better way than that, just an example). (可能有更好的方法,只是一个例子)。 Using that, or something like that, you might be able to put your small map higher up in the document tree, which would prevent it from clipping. 使用它或类似的东西,您可能能够将您的小地图放在文档树中更高的位置,这样可以防止它被裁剪。

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

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