简体   繁体   English

嵌套绝对,固定和相对元素的z-index和宽度问题

[英]z-index & width issue with nested absolute, fixed and relative elements

I am building a complex webapp using React and I'm trying to figure out the smartest way to handle a complex positioning and layering situation. 我正在使用React构建一个复杂的webapp,我正试图找出处理复杂定位和分层情况的最智能方法。

I'm wondering if I need to rethink my entire structure or just tweak some css values. 我想知道我是否需要重新考虑我的整个结构或只是调整一些css值。

The code below explains my issues: 下面的代码解释了我的问题:

 aside { position: absolute; top: 0; left: 0; width: 20%; height: 100vh; background: blue; color: white; } main { position: absolute; overflow: hidden; background-image: url('https://i.ytimg.com/vi/6sta6Gkpgcw/maxresdefault.jpg'); background-size: cover; top: 0; left: 20%; width: 80%; height: 100vh } .page-wrap { position: relative; width: 100%; height: 100vh; overflow: auto; } .overlay { position: fixed; z-index: 1; padding: 40px; color: white; font-size: 24px; width: calc(80% - 80px); height: 100vh; background-color: rgba(0, 0, 0, .5); } ul { position: relative; z-index: 2; list-style: none; color: white; font-size: 24px; line-height: 2em; padding-top: 100vh; } ul li { display: inline-block; width: 200px; height: 200px; text-align: center; padding: 20px; background: #ccc; color: red; margin: 50px; } button { padding: 10px 30px; background: green; color: white; font-size: 24px; } 
 <aside> SIDEBAR </aside> <main> <section class="page-wrap"> <div class="overlay"> <button> This needs to be clickable even though the list is on top </button> <div> <h1>My issues here are:</h1> <ol> <li>the green button is covered (disabled) by the list</li> <li>the overlay covers the scrollbar on its parent page-wrap section</li> </ol> </div> </div> <ul> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>6</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> <li>vew</li> <li>Item</li> </ul> </section> </main> 

FIDDLE 小提琴

My solution was to restructure the DOM so the body had the overflow. 我的解决方案是重构DOM,以便身体有溢出。 I had been trying to avoid this because it's a large webapp with a lot of components and pages, many of which suffered collateral damage, but ultimately, it solved my problem. 我一直试图避免这种情况,因为它是一个包含大量组件和页面的大型Web应用程序,其中许多都遭受了附带损害,但最终,它解决了我的问题。

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

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