gpt4 book ai didi

html - 使用 CSS::before 在 HTML 元素后面覆盖页面

转载 作者:太空宇宙 更新时间:2023-11-04 12:49:39 27 4
gpt4 key购买 nike

我想制作一个模态对话框,我希望对话框后面的背景通过覆盖DIV 可视化变灰。我的问题是覆盖 DIV 也覆盖了我的对话框,即使我用 CSS 的 ::before 设置了它的样式并且它有一个较低的 z-index ;我当然只希望 DIV 覆盖主窗体控件而不是我的对话框。

HTML:

<input text="Main form control example" type="text" />
<fieldset id="MainContent_fileExplorer_fsDialog" class="fileexplorer">
<legend>File explorer</legend>
<div id="MainContent_fileExplorer_pPath">
<label for="MainContent_fileExplorer_txtFullPath">Path:</label>
<input type="text" id="MainContent_fileExplorer_txtFullPath">
</div>
<div>
Form controls
</div>
<menu>
<input type="submit" value="Ok" id="MainContent_fileExplorer_butSelect">
<input type="submit" value="Cancel" id="MainContent_fileExplorer_butCancel">
</menu>
</fieldset>

CSS:

/* File explorer fieldset */
fieldset.fileexplorer {
color: #000;
position: fixed;
margin: auto;
top: 0;
left: 35%;
z-index: 1000;
box-shadow: 0 0 2em #888;
}

/* Gray out all elements except fieldset.fileexplorer */
fieldset.fileexplorer::before {
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
position: fixed;
left: 0;
top: 0;
content: "";
z-index: 999;
}

最佳答案

如果没有一些肮脏的技巧,这是不可能的。这是一个有效的 fiddle :

编辑:(更正了 dom 结构中的一个错误,现在它是一个不那么“肮脏的 hack”)

http://jsfiddle.net/zqhnyo7s/1/

我使用了 z-index: -1,它不受官方支持,但有效。

.container {
position: relative;
z-index: 1;
}

.main_form_input {
position: relative;
z-index: -1;
}

/* File explorer fieldset */
fieldset.fileexplorer {
color: #000;
position: relative;
margin-left: auto;
margin-right: auto;
width: 300px;
top: 0px;
left: 0px;
box-shadow: 0 0 2em #888;
background-color:#FFF;
}

fieldset.fileexplorer:before {
width: 1000%;
height: 1000%;
background-color: rgba(0,0,0,0.5);
position: fixed;
left: -100%;
top: -100%;
content: "";
z-index: -1;
}

关于html - 使用 CSS::before 在 HTML 元素后面覆盖页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26230361/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com