简体   繁体   English

CSS固定/绝对定位到更早的亲戚?

[英]CSS Fixed / Absolute positioning to an earlier relative?

I have a sort of super special-case here I guess. 我猜这里我有一种超级特例。

I'm working with many includes. 我正在与许多包括。 Right now I'm coding in an included content-file. 现在,我正在编写一个包含的内容文件。 There I need a lightbox which has a 20% black background covering the whole page, including the header which is fixed itself and set in prior PHP files to z-index 200. 在那里,我需要一个灯箱,该灯箱具有覆盖整个页面的20%黑色背景,其中包括标头,该标头是固定的,并且在以前的PHP文件中设置为z-index 200。

The #overlay-wrapper is, because of these includes, placed in #content , which is for other reasons position: relative . 由于包含这些内容,因此#overlay-wrapper放置在#content ,该内容由于其他原因position: relative The wrapper has 100% width and height and z-index of 1000. Still, logically, it only covers the content-area and not the whole viewport. 包装器的宽度和高度为100%,z-index为1000。从逻辑上讲,它仅覆盖内容区域,而不覆盖整个视口。

Basically I now need a way to tell the #overlay-wrapper to be positioned relatively to the body without telling the content not to be relative, because as mentioned I need it to be relative in other cases. 基本上,我现在需要一种方法来告诉#overlay-wrapper相对于身体放置,而又不告诉内容不是相对的,因为如上所述,在其他情况下,我需要将其相对。

Putting the overlay in another file would be a pain and I'm just curious if it's possible to tell a box to be positioned relatively to an "earlier" parent and not just the first he finds. 将覆盖物放置在另一个文件中会很痛苦,我只是好奇是否可以告诉盒子相对于“较早的”父母,而不仅仅是他发现的第一个父母。

As long as #overlay-wrapper is within #content and #content is relatively positioned, #overlay-wrapper will always be positioned relative to #content . 只要#overlay-wrapper#content内并且#content相对定位, #overlay-wrapper就会始终相对于#content定位。 There is no way to work around this without relocating #overlay-wrapper in the DOM. 如果不在DOM中重新定位#overlay-wrapper ,就无法解决此问题。

You will need to move #overlay-wrapper out of #content , either by modifying your PHP includes (by perhaps even moving it to a separate include of its own and including that elsewhere), or by using JavaScript to relocate it on page load. 您将需要通过修改您的PHP包含(可能甚至将其移至其自身的独立包含,并包括其他位置的内容)来将#overlay-wrapper移出#content ,或使用JavaScript在页面加载时将其重新定位。

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

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