
批改狀態(tài):合格
老師批語:
<!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>定位實(shí)戰(zhàn):模態(tài)框</title>
</head>
<body>
<header>
<h2>朱老師的博客</h2>
<button onclick="document.querySelector('.modal').styel.display='block'">
登錄
</button>
</header>
<!-- 模態(tài)框 -->
<div class="modal">
<!-- 半透明的遮罩 -->
<div class="modal-bg"></div>
<!-- 彈層表單 -->
<form action="" class="modal-form">
<fieldset style="display: grid; gap: 1em">
<legend>用戶登錄123</legend>
<input type="email" name="email" placeholder="123123@qq.com" />
<input type="password" name="password" placeholder="不少于6位" />
<button>登錄</button>
</fieldset>
</form>
</div>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #eee; /* 背景 */
}
header {
background-color: lightseagreen;
padding: 0.5em 1em;
display: flex;
}
header button {
margin-left: auto;
width: 4em;
}
.modal {
/* 把模態(tài)框容器轉(zhuǎn)為“定位元素” */
position: relative;
}
.modal .modal-form fieldset {
background-color: lightcyan;
border: none;
padding: 2em;
box-shadow: 0 0 5px #888;
}
.modal .modal-form fieldset legend {
padding: 5px 1em;
background-color: rebeccapurple;
color: ■ white;
}
.modal .modal-form {
/* 固定定位 */
position: fixed;
top: 10em;
left: 20em;
right: 20em;
}
/* 半透明的遮罩 */
.modal .modal-bg {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgb(0 0 0 0.5);
}
/* 模態(tài)框藏起來代碼 */
.modal {
display: none;
}
</style>
</body>
</html>
在CSS布局中,flex、grid以及float屬性的差別是flex屬性適用于小的UI元素,grid屬性適合用于為網(wǎng)站整體進(jìn)行布局而float屬性適合在較大的文本文章中設(shè)置圖像
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號