【问题标题】:css newly created div should go behind previous divcss 新创建的 div 应该落后于之前的 div
【发布时间】:2019-02-26 11:52:35
【问题描述】:

在这里,我正在尝试创建浏览器选项卡。

JsFiddle

.intrnlTabs {
    background: #f0f1f3;
    height: 35px
}
.intrnlTab {
    background: #e7e9ec;
    display: inline-block;
    height: 30px;
    text-align: left;
    margin-top: 5px;
    line-height: 35px;
    border-top-left-radius: 10px;
    position: relative;
    margin-left: 12px
}
.intrnlTxt {
    display: inline-block;
    max-width: 150px;
    height: inherit;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    min-width: 30px;
    padding: 0 20px 0 10px
}
.intrnlCls {
    position: absolute;
    right: -23px;
    height: inherit;
    background: #dee1e5;
    box-sizing: border-box;
    top: 0;
    width: 33px;
    transform: skewX(30deg);
    border-top-right-radius: 5px;
    cursor: pointer;
    display: inline-block;
    text-align: center
}
.intrnlCls:hover {
    background: #d7d8d8
}
.intrnlClsicon {
    transform: skewX(-30deg);
    display: inline-block
}

输出我得到的东西

输出我的期望

我希望新添加的选项卡标题应该放在前一个选项卡的后面而不添加 z-index 值。我已经实现了添加 z-index 值。但是,我不想添加 z-index 值。

【问题讨论】:

  • .intrnlCls { z-index:1; } 完成……
  • 你能解释一下为什么不想使用z-index吗?这将完全影响可能答案的范围。
  • @MrLister 我猜他们的意思是他们不想计算基于元素索引或其他什么的特定 z-index 值,并且不知道这一点需要一个“静态”的。
  • @MrLister 选项卡不是静态的。它是动态创建的。所以,我不想使用脚本添加 z-index。
  • @04FS 是的。我不知道这个静态代码z-index:1 会解决这个问题。

标签: css transform


【解决方案1】:

你不需要为每个项目计算一个特定的 z-index,或者通过JS分配它开始。

为这些“X”项目添加 1 的 z-index 就足以实现您想要的:

.intrnlCls { z-index:1; }

【讨论】:

    猜你喜欢
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 2015-03-17
    • 1970-01-01
    • 2014-01-29
    • 1970-01-01
    相关资源
    最近更新 更多