gpt4 book ai didi

css - 将固定元素定位在 float 元素之上

转载 作者:太空宇宙 更新时间:2023-11-04 14:59:05 24 4
gpt4 key购买 nike

我正在尝试将固定元素定位在 float 元素之上。为此,我正在使用 z-index 属性,但它似乎不适用于固定元素。

在这个例子中,我试图将单词 text 放置在白色 float 框上。 http://jsfiddle.net/imac/Pkrqw/1/

有没有可能做我想做的事?

这些是我正在应用的样式:

.footer{
position:fixed;
bottom:0;
width:100%;
height:40px;
background:#ccc;
color:#000;
}

.floatingBox{
position:absolute;
bottom:0;
width:480px;
height:80px;
background:#fff;
border:1px solid #000;
left:80px;

z-index:100; /* LOWER THAN .text Z-INDEX*/
}
.text{
display:inline;
z-index:999; /* HIGHER THAN .floatingBox Z-INDEX*/
}

这是示例的 HTML:

<div class="floatingBox"></div>
<div class="footer"> This is just a demo <div class="text">text</div></div>

最佳答案

您需要为 text div 指定位置,以便 z-index 生效。只需添加:

.text{
display:inline;
z-index:999; /* HIGHER THAN .floating Z-INDEX*/
position: relative;
}

关于css - 将固定元素定位在 float 元素之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16649022/

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