141 lines
3.9 KiB
Markdown
141 lines
3.9 KiB
Markdown
![]() |
---
|
||
|
id: 5a94fe5469fb03452672e461
|
||
|
title: auto-fill を使用して柔軟なレイアウトを作成する
|
||
|
challengeType: 0
|
||
|
videoUrl: 'https://scrimba.com/p/pByETK/cmzdycW'
|
||
|
forumTopicId: 301126
|
||
|
dashedName: create-flexible-layouts-using-auto-fill
|
||
|
---
|
||
|
|
||
|
# --description--
|
||
|
|
||
|
repeat 関数には <dfn>auto-fill</dfn> というオプションがあります。 これにより、希望するサイズの行または列を、コンテナのサイズに応じて可能な限り多く自動的に挿入できます。 以下のように `auto-fill` と `minmax` を組み合わせて柔軟なレイアウトが作成できます:
|
||
|
|
||
|
```css
|
||
|
repeat(auto-fill, minmax(60px, 1fr));
|
||
|
```
|
||
|
|
||
|
コンテナのサイズが変更されると、この設定では 60px の列が挿入され続け、次の列を挿入できるようになるまで引き伸ばし続けます。 **注:** コンテナがすべてのアイテムを 1 行に収められない場合、アイテムは新しい行に移動します。
|
||
|
|
||
|
# --instructions--
|
||
|
|
||
|
1 つ目のグリッドで `auto-fill` と `repeat` を使用して、最小幅 `60px` 最大幅 `1fr` の列でグリッドを埋めます。 次に、プレビューのサイズを変更して、auto-fill の動作を確認してください。
|
||
|
|
||
|
# --hints--
|
||
|
|
||
|
`container` クラスは `repeat` と `auto-fill` が設定された `grid-template-columns` プロパティを持ち、最小幅が `60px` で最大幅が `1fr` の列でグリッドを埋めるようにします。
|
||
|
|
||
|
```js
|
||
|
assert(
|
||
|
code.match(
|
||
|
/.container\s*?{[\s\S]*grid-template-columns\s*?:\s*?repeat\s*?\(\s*?auto-fill\s*?,\s*?minmax\s*?\(\s*?60px\s*?,\s*?1fr\s*?\)\s*?\)\s*?;[\s\S]*}/gi
|
||
|
)
|
||
|
);
|
||
|
```
|
||
|
|
||
|
# --seed--
|
||
|
|
||
|
## --seed-contents--
|
||
|
|
||
|
```html
|
||
|
<style>
|
||
|
.item1{background:LightSkyBlue;}
|
||
|
.item2{background:LightSalmon;}
|
||
|
.item3{background:PaleTurquoise;}
|
||
|
.item4{background:LightPink;}
|
||
|
.item5{background:PaleGreen;}
|
||
|
|
||
|
.container {
|
||
|
font-size: 40px;
|
||
|
min-height: 100px;
|
||
|
width: 100%;
|
||
|
background: LightGray;
|
||
|
display: grid;
|
||
|
/* Only change code below this line */
|
||
|
|
||
|
grid-template-columns: repeat(3, minmax(60px, 1fr));
|
||
|
|
||
|
/* Only change code above this line */
|
||
|
grid-template-rows: 1fr 1fr 1fr;
|
||
|
grid-gap: 10px;
|
||
|
}
|
||
|
|
||
|
.container2 {
|
||
|
font-size: 40px;
|
||
|
min-height: 100px;
|
||
|
width: 100%;
|
||
|
background: Silver;
|
||
|
display: grid;
|
||
|
grid-template-columns: repeat(3, minmax(60px, 1fr));
|
||
|
grid-template-rows: 1fr 1fr 1fr;
|
||
|
grid-gap: 10px;
|
||
|
}
|
||
|
</style>
|
||
|
<div class="container">
|
||
|
<div class="item1">1</div>
|
||
|
<div class="item2">2</div>
|
||
|
<div class="item3">3</div>
|
||
|
<div class="item4">4</div>
|
||
|
<div class="item5">5</div>
|
||
|
</div>
|
||
|
<div class="container2">
|
||
|
<div class="item1">1</div>
|
||
|
<div class="item2">2</div>
|
||
|
<div class="item3">3</div>
|
||
|
<div class="item4">4</div>
|
||
|
<div class="item5">5</div>
|
||
|
</div>
|
||
|
```
|
||
|
|
||
|
# --solutions--
|
||
|
|
||
|
```html
|
||
|
<style>
|
||
|
.item1{background:LightSkyBlue;}
|
||
|
.item2{background:LightSalmon;}
|
||
|
.item3{background:PaleTurquoise;}
|
||
|
.item4{background:LightPink;}
|
||
|
.item5{background:PaleGreen;}
|
||
|
|
||
|
.container {
|
||
|
font-size: 40px;
|
||
|
min-height: 100px;
|
||
|
width: 100%;
|
||
|
background: LightGray;
|
||
|
display: grid;
|
||
|
/* Only change code below this line */
|
||
|
|
||
|
grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
|
||
|
|
||
|
/* Only change code above this line */
|
||
|
grid-template-rows: 1fr 1fr 1fr;
|
||
|
grid-gap: 10px;
|
||
|
}
|
||
|
|
||
|
.container2 {
|
||
|
font-size: 40px;
|
||
|
min-height: 100px;
|
||
|
width: 100%;
|
||
|
background: Silver;
|
||
|
display: grid;
|
||
|
grid-template-columns: repeat(3, minmax(60px, 1fr));
|
||
|
grid-template-rows: 1fr 1fr 1fr;
|
||
|
grid-gap: 10px;
|
||
|
}
|
||
|
</style>
|
||
|
<div class="container">
|
||
|
<div class="item1">1</div>
|
||
|
<div class="item2">2</div>
|
||
|
<div class="item3">3</div>
|
||
|
<div class="item4">4</div>
|
||
|
<div class="item5">5</div>
|
||
|
</div>
|
||
|
<div class="container2">
|
||
|
<div class="item1">1</div>
|
||
|
<div class="item2">2</div>
|
||
|
<div class="item3">3</div>
|
||
|
<div class="item4">4</div>
|
||
|
<div class="item5">5</div>
|
||
|
</div>
|
||
|
```
|