MTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>模态框</title>
<link rel="stylesheet" href="/HTML/css/modal.css" />
</head>
<body>
<header>
<h2 class="title">晖创财务</h2>
<button onelick="showmodal()">登录</button>
</header>
<!-- 模态框 -->
<div class="modal">
<!-- 1半透明遮罩 -->
<div class="modal-bg" onclick="cloaemodal()"></div>
<!-- 2弹层表单 -->
<form action="" class="modal-form">
<fieldset style="display: grid; gap: 1em">
<legend>
<button>账号登录</button>
<button>短息登录</button>
</legend>
<input type="admin" name="name" id="" placeholder="账号" />
<input type="user" name="usser" id="" placeholder="密码(8位数以上)" />
<button class="box1">登录</button>
</fieldset>
</form>
</div>
</body>
</html>
CSS
/* 初始化 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 头部样式 */
header {
background-color: cornflowerblue;
padding: 0.5em 1em;
display: flex;
}
/* logo */
header .title {
color: white;
letter-spacing: 5px;
text-shadow: 1px 1px 1px #555;
}
/* 登录按钮 */
header button {
margin-left: auto;
width: 5em;
border: none;
border-radius: 0.5em;
}
header button:hover {
cursor: pointer;
background-color: pink;
color: #fff;
box-shadow: 0 0 5px #fff;
transition: 0.3s;
}
/* 模态框 */
.modal .modal-form fieldset {
height: 15.5em;
background-color: lightcyan;
border: none;
padding: 2em 3em;
box-shadow: 0 0 0 5px lavender;
}
/* 模态框表单标题 */
.modal .modal-form fieldset legend {
padding: 0px 0px;
width: 300px;
box-shadow: 0 0 0 0px cornflowerblue;
background-color: cornflowerblue;
}
/* 定位 */
.modal .modal-form {
position: fixed;
top: 10em;
left: 30em;
right: 30em;
}
/* 遮罩 固定定位 */
.modal .modal-bg {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.281);
}
div button:hover {
background-color: coral;
color: #fff;
box-shadow: 0 0 5px #fff;
font-size: ;
transition: 0.1s;
}
legend button {
padding: 4px 4px;
width: 148px;
font size: 14px;
}