grid: auto-placement
005.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" />
<link rel="stylesheet" href="005.css" />
<title>Auto</title>
</head>
<body>
<div class="grid">
<!-- .item*20>{$} -->
<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 class="item">10</div>
<div class="item">11</div>
<div class="item">12</div>
<div class="item">13</div>
<div class="item">14</div>
<div class="item">15</div>
<div class="item">16</div>
<div class="item">17</div>
<div class="item">18</div>
<div class="item">19</div>
<div class="item">20</div>
<div class="item">21</div>
<div class="item">22</div>
<div class="item">23</div>
<div class="item">24</div>
<div class="item">25</div>
<div class="item">26</div>
<div class="item">27</div>
<div class="item">28</div>
<div class="item">29</div>
<div class="item">30</div>
<div class="item">31</div>
<div class="item">32</div>
<div class="item">33</div>
<div class="item">34</div>
<div class="item">35</div>
<div class="item">36</div>
<div class="item">37</div>
<div class="item">38</div>
<div class="item">39</div>
<div class="item">40</div>
<div class="item">41</div>
<div class="item">42</div>
<div class="item">43</div>
<div class="item">44</div>
<div class="item">45</div>
<div class="item">46</div>
<div class="item">47</div>
<div class="item">48</div>
<div class="item">49</div>
<div class="item">50</div>
</div>
</body>
</html>
005.html
.grid {
background-color: black;
color: white;
display: grid;
gap: 5px;
height: 100vh;
grid-template-columns: repeat(4, 100px);
grid-template-rows: repeat(4, 100px);
}
.item:nth-child(odd) {
background-color: springgreen;
}
.item:nth-child(even) {
background-color: deepskyblue;
}
grid-auto-rows
grid-auto-flow
grid-auto-columns
번외(Grid Garden)
여러 포스트에 걸쳐 grid layout에 대해 다뤄 봤다. 아래 게임을 해 보면서 제대로 이해해 보자.
참고
반응형
'개발(Web) > Web' 카테고리의 다른 글
[CSS] normalize.css (0) | 2022.01.24 |
---|---|
[CSS] reset.css (0) | 2022.01.23 |
[CSS] Grid Item 정렬하기 (0) | 2022.01.21 |
[CSS] Grid Container 정렬하기 (0) | 2022.01.20 |
[CSS] Grid Items 정렬하기 (0) | 2022.01.19 |