【问题标题】:Stacking absolute elements with transform使用变换堆叠绝对元素
【发布时间】:2016-07-16 05:23:00
【问题描述】:

我目前正在构建一个带有自定义绝对定位下拉菜单的表单。其他输入字段使用transform: translateY 进行动画处理。但是,我根本无法将下拉列表堆叠在以下输入元素的顶部。我已将问题简化为以下内容:

html:

<div class="a"></div>
<div class="a top">
    <div class="b"></div>
</div>
<div class="a"></div>

css:

.a {
    transform: translateY(10px);
    position: "relative";
    background: red;
    height: 50px;
    margin-top: 10px;
    z-index: 1;
    opacity: 0.8;
}
.b {
    position: "absolute";
    top: 0;
    height: 100px;
    width:25px;
    background: blue;
}
.input.top {
    z-index: 10;
}  

以下小提琴说明了我的问题: https://jsfiddle.net/m817ffqy/1/

我已经尝试过transform-style: flat 和设置translateZ,但我无法获得想要的效果..

【问题讨论】:

    标签: html css z-index css-transforms


    【解决方案1】:

    代替:

    position: "relative";
    position: "absolute";
    

    尝试:

    position: relative;
    position: absolute;
    

    另外,.input.top 需要position: relativeposition: absolute

    【讨论】:

    • 虽然你的语法是正确的,但在演示中似乎没有什么不同。此外,.input.top 不起作用,因为 HTML 中没有 .input 类。另外,所有元素都是relativeabsolute
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多