Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
以下代码展示大屏适配,浏览器在大于960px,481~959px,低于480px
时自动适配,下列三个按钮得大小
<!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>
</head>
<body>
<button class="btn first">按钮1</button>
<button class="btn sec">按钮2</button>
<button class="btn three">按钮3</button>
</body>
<style>
html {
font-size: 10px;
}
.btn {
background-color: blue;
color: brown;
border: none;
outline: none;
}
.btn:hover {
cursor: pointer;
opacity: 0.8;
transition: 0.3s;
padding: 0.4rem 0.8rem;
}
.btn.first {
font-size: 1rem;
}
.btn.sec {
font-size: 1.5rem;
}
.btn.three {
font-size: 2.2rem;
}
@media (min-width: 960px) {
html {
font-size: 40px;
}
}
@media (min-width: 481px) and (max-width: 959px) {
html {
font-size: 20px;
}
}
@media (max-width: 480px){
html {
font-size: 10px;
}
}
</style>
</html>
<!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>Document</title>
</head>
<body>
<header>
<h1 class="title">固定定位演示</h1>
<button onclick="document.querySelector('.modal').style.display='block'">登录</button>
</header>
<div class="modal">
<div class="modal-bg" onclick="this.parentNode.style.display='none'"></div>
<form action="" class="modal-form">
<fieldset style="display: grid; gap: 1em">
<legend>用户登录</legend>
<input type="email" name="email" placeholder="user@email.com" />
<input type="password" name="password" placeholder="不少于6位" />
<button>登录</button>
</fieldset>
</form>
</div>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
header {
background-color: cyan;
display: flex;
padding: 0.5em 1em;
}
.title {
font-weight: lighter;
font-style: italic;
color: white;
text-shadow: 1px 1px 1px #555;
letter-spacing: 1px;
}
header button {
margin-left: auto;
width: 5em;
border: none;
border-radius: 0.5em;
}
header button:hover {
cursor: pointer;
background-color: coral;
color: white;
box-shadow: 0 0 5px #fff;
transition: 0.3s;
}
.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);
}
/* 初始化时将模态框弹层隐藏 */
.modal {
display: none;
}
</style>
</body>
</html>
<!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>Document</title>
</head>
<body>
<div class="container">
<p class="item">item1</p>
<p class="item">item2</p>
<p class="item">item3</p>
<p class="item">item4</p>
<p class="item">item5</p>
</div>
</body>
<style>
.container {
display: flex;
flex-flow: row nowrap;
height: 20em;
border: 1px solid #000;
place-content: center;
}
.item {
width: 5em;
border: darkgoldenrod;
background-color: darkorange;
margin: 20px;
}
.container :first-of-type {
background-color: darkturquoise;
order: 5;
}
.container :last-of-type {
background-color: deeppink;
order: -1;
}
</style>
</html>