gpt4 book ai didi

html - 什么条件会绑定(bind)位置 : fixed element to its parent's box?

转载 作者:太空宇宙 更新时间:2023-11-04 10:04:45 25 4
gpt4 key购买 nike

我正在尝试为菜单制作背景,用于检测用户是否单击了菜单以外的其他地方并关闭菜单。

出于某种原因尽管设置

.menu-backdrop {
position: fixed;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
}

背景不会超出其中一个父 div。

我已将网页提炼成一些简单的内容并将其粘贴在这里 http://codepen.io/ben_irule/pen/LZWwjL?editors=1100

<!DOCTYPE html>
<html>
<head>
<style>
.app-layout {
height: 100%;
}

.layout {
height: calc(100% - 35px);
display: block;
}

footer {
height: 35px;
background-color: green;
}

.content {
position: relative;

/* attribute of doom*/
transform: translate3D(0, 0, 0);

display: block;
height: 100%;
margin-left: 320px;
margin-right: 280px;
}

.menu-backdrop {
position: fixed;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
background-color: blue;
}

html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}

</style>
</head>

<body>
<div class="app-layout">
<div class="layout">
<div class="content">
<div class="menu-backdrop"></div>
</div>
</div>
<footer></footer>
</div>
</body>
</html>

我注意到一个转换属性,当禁用该属性时,父 div 不会出现问题。但是,当我在完整的应用程序中禁用等效属性时,它并没有解决问题。

我有兴趣了解哪些条件会导致固定位置元素被父 div 绑定(bind)。

我整个上午都在网上搜索,但没有找到任何与我当前问题相似的内容。

最佳答案

.content {
position: relative;

/* attribute of doom*/
transform: translate3D(0, 0, 0);

display: block;
height: 100%;
margin-left: 320px;
margin-right: 280px;
}

margin left 和 margin right 是阻止你超越现在的东西。尝试减少它。


这是一个更好的方法。看看这是否能解决您的问题。由于您有特定的编号边距,请将它们添加到菜单背景中。

 .menu-backdrop {
position: fixed;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
margin-left: -320px;
margin-right: -280px;
margin-bottom: -32px;
background-color: blue;
}

关于html - 什么条件会绑定(bind)位置 : fixed element to its parent's box?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38109015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com