【问题标题】:Z-index doesn't work with positionsZ-index 不适用于位置
【发布时间】:2016-12-05 19:41:04
【问题描述】:

我正在尝试创建一个弹出窗口,但我遇到了 z-index 和位置问题。

.filterBar如下:

.filterBar{
    position: fixed;
    z-index: 3;
    left: 275px;
    right: 15px;
    display: flex;
    align-items: center;
    height: 40px;
    background-color: #f9f9f9;
}

outter(需要全身)如下:

#outter{
    z-index: 99999999;
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0px;
    left: 0px;
    bottom: 0px;
    right: 0px;
    width: 100%;
    height: 100%;
    background: rgba(22, 23, 23, 0.8);
}

有了这个样式,我得到了下一个:

因此,过滤栏在outter div之前,不管outter有更大的z-index。

如果我从 .filterBar 类中删除 z-index: 3,那么一切正常。

但我无法删除 z-index,因为我需要它来设置页面其余部分的样式。

【问题讨论】:

标签: html css sass


【解决方案1】:

这是因为display: flex 元素。当您使用弹性项目时,它们会显示为内联块元素。

[> 4.3。弹性项目 Z 排序

Flex 项目的绘制与内联块 [CSS21] 完全相同,除了 该订单修改文档订单用于代替原始文档 order 和 z-index 值而不是 auto 创建堆叠上下文 即使位置是静态的。][1]

您需要将display: flex 应用于body

【讨论】:

  • 它不起作用。我从我的样式中删除了 display: flex,但它仍然不起作用。
  • 试着用一个例子做一个 jsfiddle 我会尽力帮助你。
猜你喜欢
  • 2013-01-07
  • 2014-10-20
  • 2022-10-17
  • 1970-01-01
  • 2016-02-22
  • 2011-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多