Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:容器与项目, 就是父元素和子元素, 只是场景不同, 换了个名字罢了
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>grid网格中所有项目的整体对齐方式</title>
<style>
*:not(body){
outline: red 1px dashed;
}
.container{
width: 500px;
height: 400px;
font-size: 2rem;
/*grid布局*/
display: grid;
grid-template-columns: repeat(3,100px);
grid-template-rows: repeat(3,80px);
/*间隙*/
grid-gap: 10px;
/*设置项目在网格容器中的对齐方式*/
/*水平对齐方式*/
/*默认在起始方向*/
/*justify-content: start;*/
/*水平居中*/
/*justify-content: center;*/
/*在最右侧 (终止边线)*/
/*justify-content: end;*/
/*垂直方向对齐*/
/*默认在起始方向*/
/*align-content: start;*/
/*垂直居中*/
/*align-content:center;*/
/*最下面(终止边线)*/
/*align-content:end;*/
/*对齐方式的简写 第一个是 垂直 第二个是水平 */
/*place-content: start center;*/
/*项目中的内容对齐*/
/*水平方向*/
/*默认 拉伸*/
/*justify-items: stretch;*/
/*最左边(起始位置)*/
/*justify-items: start;*/
/*最右边 (最后面)*/
/*justify-items: end;*/
/*居中*/
/*justify-items: center;*/
/*垂直方向*/
/*默认值*/
/*align-items: stretch;*/
/*最上面(起始位置)*/
/*align-items: start;*/
/*垂直居中*/
/*align-items: center;*/
/*垂直最下面*/
/*align-items: end;*/
/*简写 第一个属性是 垂直 第二个是水平*/
/*place-items: end start;*/
}
.container > .item{
background-color: yellow;
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>grid中某一个项目的对齐方式</title>
<style>
*:not(body){
outline: 1px red dashed;
}
/*网格容器*/
.container{
width: 600px;
font-size: 2rem;
/*grid布局*/
display: grid;
grid-template-columns: repeat(3,1fr);
grid-template-rows: repeat(3,150px);
grid-gap: 10px;
}
.container > .item:first-of-type{
width: 100px;
height: 100px;
background-color: #63a35c;
text-align: center;
/*项目在容器中的对齐方式*/
/*水平方向*/
/*默认在起始*/
/*justify-self: stretch;*/
/*水平居中*/
/*justify-self: center;*/
/*水平最后*/
/*justify-self: end;*/
/*垂直方向*/
/*默认起始方向*/
/*align-self: stretch;*/
/*垂直居中*/
/*align-self: center;*/
/*垂直最后*/
/*align-self: end;*/
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
</body>
</html>