【问题标题】:Div is laying ontop of absolute-positioned element. How to put element above the div?Div 位于绝对定位元素之上。如何将元素放在div之上?
【发布时间】:2011-09-30 01:31:32
【问题描述】:

我在页面上有几个控件。其中一个是按钮,另一个是宽度为 100% 的 div。按钮的位置:绝对。

我的按钮 CSS -- 现在只是在玩弄它:

.toggleButton
{
    z-index: 99999999px;
    position: absolute;
    margin-top: 2px;
    right: 130px;
}

div 是自动生成的,但这里是它的计算样式:

background-color: transparent;
clear: both;
color: dimGray;
display: block;
font-family: 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
font-size: 11px;
height: 26px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
min-height: 0px;
overflow-x: hidden;
overflow-y: hidden;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
position: relative;
width: 1026px;

我想知道如何将按钮放在 div 上。在当前状态下,无法在所有位置单击该按钮。我不想限制 div 的宽度,只需将按钮放在它上面。

【问题讨论】:

    标签: css


    【解决方案1】:

    z-index 不是 px 单位。因此,将 div 的 z-index 设置为 1,并将按钮的 z-index 设置为 20。

    .toggleButton
    {
        z-index: 20;
        position: absolute;
        margin-top: 2px;
        right: 130px;
    }
    

    我需要一个参考,但我很确定 z-index 的上限为 100,所以像 9999999 这样的时髦大数字只会被认为是 100。

    【讨论】:

    • 我相信这取决于浏览器,但我相信一般上限接近 10k。请参阅stackoverflow.com/questions/491052/… 了解更多信息。
    • 根据the spec,没有定义的最大值。过去我用过 100 多个,没有任何问题。
    • 啊,小错误……应该知道的。那好吧。非常感谢,我会在有能力的时候接受答案。这行得通。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-23
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多