css - 绝对定位的 div 嵌套在另一个绝对定位的 div 中的问题

标签 css css-position

我不是 CSS 专家,尤其是在定位方面,我希望这个问题很容易解决。

这是我简化的 HTML:

<body>
    <div style="height:100%;width:100%;">
        <div id="map" style="bottom:250px;height:100%;overflow:hidden;position:absolute;width:100%;">
            <!-- The controls div does not render correctly. -->
            <div id="controls" style="left:10px;position:absolute;top:10px;">
            </div>
            <!-- The legend and logos divs do render correctly. -->
            <div id="legend" style="bottom:45px;left:10px;position:absolute;">
            </div>
            <div id="logos" style="bottom:5px;left:10px;position:absolute;">
            </div>
        </div>
        <div id="search" style="bottom:0;height:250px;position:absolute;width:100%;">
        </div>
    </div>
</body>

“控件”div 未正确呈现。事实上,它根本不显示。如果我去掉“top:10px;”样式,并将其替换为“bottom:400px;”,它确实正确呈现。不过,这不是我想要的,因为如果用户调整浏览器窗口的大小,“ map ”div 的高度会得到调整。我也不想使用 JavaScript 来定位 div。

“图例”和“ Logo ”div 都正确呈现。

我正在 Firefox 中进行测试。

最佳答案

您只需将 parent div 的位置设置为 relativechildren absolute。此处解释了此 CSS 技巧:

关于css - 绝对定位的 div 嵌套在另一个绝对定位的 div 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4411517/

相关文章:

html - 缩小整个网站后,如何使固定位置居中?

html - 强制表单元素水平滚动的CSS布局

html - 如何设置 float div相对于邻居的宽度

html - 如何只选择另一个 div 的所有第一个 child

css - 位置: fixed is applied?时是否可以保持父元素的宽度

html - DIV 溢出到页 footer 分 HTML CSS

html - border-bottom 没有按预期工作

html - 将一个 div 放置在另一个 div 的中间

javascript - 修复了标题和自动滚动到 Div 的问题

javascript - 动画 {"Top"} 如何在顶部位置停止滚动 div 为 0 px - Jquery