gpt4 book ai didi

html - 具有部分不透明灰色背景的对话窗口

转载 作者:太空宇宙 更新时间:2023-11-04 06:44:33 26 4
gpt4 key购买 nike

当用户单击链接时,我想创建一个位于浏览器窗口中心的“弹出”对话框,其灰色与此非常相似:

Chrome Confirmation Dialog Box

请注意,用户可以单击对话框外的任意位置以将其关闭。

我试过关注 this example , 但它只是在像这样的白页中创建一个黑色条纹:

Bad result - black stripe

这是我的代码:

function blah() {
var gab = document.createElement('div');
gab.setAttribute('id', 'OVER');
gab.innerHTML='<div class="overlay"><h1>hello</h1></div>';
document.body.appendChild(gab);
}
#OVER {
width:100%;
height:100%;
left:0;/*IE*/
top:0;
text-align:center;
z-index:5;
position:fixed;
background-color:#fff;
}
.overlay {
width:100%;
z-index:6;
left:0;/*IE*/
top:30%;
font-color:#cdcdcd;
font-size:0.8em;
text-align:center;
position:fixed;
background-color:#000;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/test.css">
</head>
<body>
<h1>This is the title</h1>
Here is some text <a href="#" onclick="blah();return false;">Click me</a>
</body>
</html>

最佳答案

这应该有效:

// JS, replace this
gab.innerHTML='<div class="overlay"><div class="dialog"><h1>hello</h1></div></div>';


// CSS
.overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.4); // 0.4 is the opacity;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}

.dialog {
background-color: #fff;
}

关于html - 具有部分不透明灰色背景的对话窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53423051/

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