Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:
<!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>使用grid实现一个12列栅格布局的组件</title>
<link rel="stylesheet" href="gird.css" />
</head>
<body>
<div class="container">
<div class="row">
<span class="item col-12">12列</span>
</div>
<div class="row">
<span class="item col-6">6列</span>
<span class="item col-6">6列</span>
</div>
<div class="row">
<span class="item col-4">4列</span>
<span class="item col-4">4列</span>
<span class="item col-4">4列</span>
</div>
<div class="row">
<span class="item col-2">2列</span>
<span class="item col-10">10列</span>
</div>
</div>
</body>
</html>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
height: 100vh;
display: grid;
place-content: center;
}
.containter {
min-width: 80vw;
display: grid;
gap: 0.5em;
}
.containter > .row {
display: grid;
/* 任何一行都是由12列组成 */
grid-template-columns: repeat(12, 1fr);
min-height: 3em;
gap: 0.5em;
}
.containter > .row > .item {
padding: 1em;
border: 1px solid;
}
.col-12 {
grid-area: auto / span 12;
}
.col-11 {
grid-area: auto / span 11;
}
.col-10 {
grid-area: auto / span 10;
}
.col-9 {
grid-area: auto / span 9;
}
.col-8 {
grid-area: auto / span 8;
}
.col-7 {
grid-area: auto / span 7;
}
.col-6 {
grid-area: auto / span 6;
}
.col-5 {
grid-area: auto / span 5;
}
.col-4 {
grid-area: auto / span 4;
}
.col-3 {
grid-area: auto / span 3;
}
.col-2 {
grid-area: auto / span 2;
}
.col-1 {
grid-area: auto / span 1;
}
<!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>使用grid实现12列栅格布局组件来完成圣杯布局</title>
<link rel="stylesheet" href="gird.css" />
</head>
<style>
.row:nth-of-type(2) {
height: 80vh;
}
</style>
<body>
<div class="containter">
<!-- 页眉0 -->
<div class="row">
<div class="item col-12 header">header</div>
</div>
<!-- 主体 -->
<div class="row">
<!-- 左2列,中间8列,右边2列 -->
<div class="item col-2 left">left</div>
<div class="item col-8 main">main</div>
<div class="item col-2 right">right</div>
</div>
<!-- 页脚 -->
<div class="row">
<div class="item col-12 footer">footer</div>
</div>
</div>
</body>
</html>