我有几个HTML元素可以创建一个显示加载微调器的对话框。它还有一个填充页面的半透明背景。它会填充除导航栏以外的整个页面。如何在CSS中屏蔽导航栏? Example
这是我的背景CSS:
.dialog {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-background-clip: padding-box;
background-clip: padding-box;
padding: 0;
margin: 0;
font: inherit;
color: inherit;
background: transparent;
border: none;
line-height: normal;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-weight: 400;
font-size: 17px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
margin: auto auto;
background-color: rgba(255, 255, 255, 0.92);
-webkit-box-shadow: 0 2px 12px rgba(0,0,0,0.07);
box-shadow: 0 2px 12px rgba(0,0,0,0.07);
overflow: hidden;
min-width: 270px;
min-height: 100px;
text-align: left;
-webkit-border-radius: 4px;
border-radius: 4px;
z-index: 999;
}
#loadingDialog {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-background-clip: padding-box;
background-clip: padding-box;
white-space: nowrap;
overflow: hidden;
word-spacing: 0;
padding: 0;
margin: 0;
font: inherit;
color: inherit;
background: transparent;
border: none;
line-height: normal;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-background-clip: padding-box;
background-clip: padding-box;
font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-weight: 400;
font-size: 17px;
overflow: hidden;
background-color: rgba(0, 0, 0, 0.7);
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
z-index:999;
}
以及相应的HTML:
<div id="loadingDialog" ng-class="loadClass">
<div class="dialog">
<div class="page">
<p style="text-align:center;margin-top:40px;opacity:0.6;"><i class="fa fa-spinner fa-spin fa-lg"></i> Loading...</p>
</div>
</div>
</div>
Navbar CSS:
.navigation-bar {
font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-weight: 400;
font-size: 17px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-background-clip: padding-box;
background-clip: padding-box;
white-space: nowrap;
overflow: hidden;
word-spacing: 0;
padding: 0;
margin: 0;
font: inherit;
color: inherit;
background: transparent;
border: none;
line-height: normal;
cursor: default;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
z-index: 2;
display: block;
height: 44px;
padding-left: 0;
padding-right: 0;
background: #fff;
color: #333;
-webkit-box-shadow: none;
box-shadow: none;
border-bottom: 1px solid #ddd;
font-weight: 400;
width: 100%;
white-space: nowrap;
overflow: visible;
}
答案 0 :(得分:1)
要使div保持在所有其他div之上,您可以使用以下代码:
body {position: relative;}
.infront {
position: absolute;
height: 100%;
width: 100%;
background: rgba(0,0,0,0.5);
z-index: 999;
}
作为css,以及打开<body>
后面的以下html代码 - 标记:
<div class="infront"><!-- your content --></div>
我的猜测是,您的导航栏保持白色,因为您已在内容区域中以某种方式嵌套了重叠的加载框,或者使用position: absolute
定位导航栏,这使其保持在其他div之前。为了避免这种情况,我添加了z-index: 999;
,它创建了一种景深,并让具有更高z-index的div保持在其他值之上。
如果您需要更精确的帮助,发布您正在使用的代码片段总是有帮助的!欲了解更多信息,请随时询问。
祝你好运, 玛丽安。
答案 1 :(得分:1)
我相信你应该使用z-index
更大的价值用于Dialogue然后使用Navbar。
示例,如果导航栏具有:
z-index:1
然后用于对话
z-index:2
您应该在问题中包含Html标记和CSS以便更好地理解。