制作简易模态框登录页面及 flex 与 grid 整理总结
制作简易模态框登录页面
<!DOCTYPE html>
<html lang="zh-CN">
<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>
<style>
/* 页面内容初始化 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 10px;
}
body {
font-size: 1.6rem;
}
a {
text-decoration: none;
color: white;
}
/* 配置模态框 */
.modal {
position: relative;
display: none;
}
/* 配置遮罩 */
.modal .modal-bgc {
position: fixed;
background-color: rgb(0, 0, 0, 0.5);
top: 0;
right: 0;
bottom: 0;
left: 0;
}
/* 配置登录表单,使用grid布局 */
.modal .modal-form {
/* 临时加入一个颜色方便布局 */
/* background-color: lightskyblue; */
position: fixed;
left: 20rem;
right: 20rem;
top: 20rem;
}
.modal .modal-form fieldset {
background-color: lightskyblue;
border: none;
display: grid;
gap: 1rem;
padding: 3rem;
box-shadow: 0 0 5px #888;
}
.modal .modal-form fieldset legend {
padding: 1rem;
background-color: hotpink;
color: white;
}
.modal .modal-form fieldset div input {
width: 100%;
}
/* 页眉使用flex布局 */
.header {
background-color: lightskyblue;
width: 100%;
height: 6rem;
display: flex;
font-size: 1.8rem;
place-content: space-between;
padding: 1rem;
}
/* 给页眉的按钮添加样式 */
.header button {
width: 6rem;
font-size: 1.8rem;
}
/* 限制一下主体中测试图片的宽度 */
.main img {
width: 100%;
}
/* 给页脚添加一些样式 */
.footer {
background-color: lightslategray;
width: 100%;
height: 10rem;
padding: 2rem 0 0 2rem;
}
.footer a:hover {
color: lightskyblue;
}
</style>
</head>
<body>
<!-- 配置模态框背景 -->
<!-- 配置登录表单 -->
<!-- 将页面分成三部分,页眉,主体,页脚 -->
<!-- 模态框 -->
<div class="modal">
<div class="modal-bgc" onclick="this.parentNode.style.display='none'"></div>
<form action="" class="modal-form">
<fieldset>
<legend>用户登录</legend>
<div class="uname">
<label for="uname">账号:</label>
<input type="text" name="uname" id="uname" placeholder="请输入账号或手机号" required />
</div>
<div class="pwd">
<label for="pwd">密码:</label>
<input type="password" name="pwd" id="pwd" placeholder="请输入密码" required />
</div>
<button>登录</button>
</fieldset>
</form>
</div>
<!-- 页眉 -->
<div class="header">
<!-- 添加一个标题跟按钮-->
<h2>超超多喝水</h2>
<button onclick="document.querySelector('.modal').style.display='block'">登录</button>
</div>
<!-- 主体 -->
<div class="main">
<img src=" 替换为图片链接" alt="" />
<img src=" 替换为图片链接" alt="" />
<img src=" 替换为图片链接" alt="" />
<img src=" 替换为图片链接" alt="" />
<img src=" 替换为图片链接" alt="" />
<img src=" 替换为图片链接" alt="" />
</div>
<!-- 页脚 -->
<div class="footer">
<span>友情链接:</span>
<a href="https://www.php.cn/">php中文网</a>
</div>
</body>
</html>
flex 整理总结
点击查看思维导图
grid 整理总结
点击查看思维导图