<!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属性</title>
</head>
<body>
<div class="container">
<div class="item">item1</div>
</div>
<hr/>
<style>
.container {
display: grid;
width: 200px;
height: 150px;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr)
}
.container .item {
background-color: yellowgreen;
grid-area: 1 /2 / span 2 / span 2;
}
</style>
<div class="container1">
<div class="item">item1</div>
<div class="item">item2</div>
<div class="item">item3</div>
<div class="item">item4</div>
<div class="item">item5</div>
<div class="item">item6</div>
<div class="item">item7</div>
<div class="item">item8</div>
<div class="item">item9</div>
<div class="item one">item10</div>
<div class="item one">item11</div>
</div>
<hr />
<style>
.container1 {
display: grid;
width: 200px;
height: 150px;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
grid-auto-flow: row;
grid-auto-rows: 1fr;
}
.container1 > .item {
background-color: seagreen;
}
.container1 > .item.one {
background-color: violet;
}
</style>
<div class="container2">
<div class="item">item1</div>
<div class="item">item2</div>
<div class="item">item3</div>
<div class="item">item4</div>
<div class="item">item5</div>
<div class="item">item6</div>
<div class="item active">item7</div>
<div class="item">item8</div>
<div class="item">item9</div>
</div>
<hr />
<style>
.container2 {
display: grid;
width: 250px;
height: 250px;
background-color:khaki;
border: 1px solid black;
grid-template-columns: repeat(3, 70px);
grid-template-rows: repeat(3, 70px);
/* place-content: center; */
/* place-content: space-between; */
place-content: space-around;
place-items: center;
}
.container2 > .item {
background-color:aquamarine;
width: 50px;
height: 50px;
}
.container2 > .item.active {
background-color: brown;
place-self: end start;
}
</style>
<div class="container3">
<div class="item">item1</div>
<div class="item">item2</div>
<div class="item">item3</div>
<div class="item">item4</div>
<div class="item">item5</div>
<div class="item">item6</div>
<div class="item">item7</div>
<div class="item">item8</div>
<div class="item">item9</div>
</div>
<style>
.container3 {
display: grid;
width: 210px;
height: 210px;
background-color:khaki;
border: 1px solid black;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 10px;
}
.container3 > .item {
background-color:aquamarine;
}
</style>
</body>
</html>