【问题标题】:Header position issue for popup overlay弹出覆盖的标题位置问题
【发布时间】:2018-07-25 13:52:17
【问题描述】:

我在 Angular 2 中工作。我的 html 页面有标题 div 和弹出覆盖 div。当我打开弹出式覆盖时,我们面临 z-index 问题,而不是仅申请标题 div。我想应用覆盖孔窗口时我打开弹出窗口。如果我改变我的标题位置是继承然后它会工作,但我不会改变我的标题位置,因为标题是固定位置。如何解决这个问题?

HTML:

header-component

 <div class="myheader"> 
 ..menus 
 </div>

弹出组件

<div class="popup"></div> 
<div class="overlay"></div>

CSS

 .overlay {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0; 
    z-index: 106; 
    width:100%;
    height:100%;
    background:#fff;
    opacity:.60;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=60)";filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=60);filter:alpha(opacity=60);
    }   

    .myheader{ 
    display: block;
    top: 0px;
    left: 0px;
    width: 100%;
    position: fixed;
    z-index: 100;
    margin: 0px;
    padding: 0px;
    background-color: #fff;
    border-bottom: 1px solid #ebebeb;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box; 
    }

【问题讨论】:

  • 尝试给覆盖的z-index一个更高的值,也许999?因为现在 .myheader.overlay 有相同的 z-index - 100
  • 请也分享 html 代码(或可以看到问题的一部分)。由于 2 个类具有相同的 z-index,因此 dom 中相关 div 的顺序可能与您的问题有关
  • 更新了 html...角度 2 中的这个问题
  • 我找不到原因。它只有在我更改 .myheader 位置“继承”时才有效..但这不正确。如果我这样更改,我将获得额外的滚动和标题移动..
  • 请任何人帮助我..

标签: css


【解决方案1】:

我已经取出了一些代码给你看,如果你只是改变 z-index,它就可以正常工作。哪个&lt;div&gt; 具有较高的z-index 将在顶部。

* {
  margin: 0;
  padding: 0;
  border: 0;
  box-sizing: border-box; 
}

.overlay, .myheader {
  position: fixed;
  top: 0;
  left: 0;
}

.overlay {
  z-index: 98; 
  color: white;
  background:black;
}   

.myheader { 
  z-index: 99;
  background-color: red;
}

* {
  margin: 0;
  padding: 0;
  border: 0;
  box-sizing: border-box; 
}

.overlay, .myheader {
  position: fixed;
  top: 0;
  left: 0;
}

.overlay {
  z-index: 98; 
  color: white;
  background:black;
}   

.myheader { 
  z-index: 99;
  background-color: red;
}
<div class="overlay">Things</div>
<div class="myheader">Stuff</div>

【讨论】:

  • Fencepencil:我已经尝试过这样......但没有工作......我也面临位置问题
  • Z-index 仅在我更改 myheader 位置时才有效:继承..但我想要固定标题。
  • 我认为问题是 myheader 并且覆盖是固定位置
  • 你有一个活生生的例子来说明你想要达到的目标吗?我们也许可以从不同的角度(ular)
  • 给几分钟
猜你喜欢
  • 1970-01-01
  • 2021-01-26
  • 2015-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多