質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
CSS3

CSS(Cascading Style Sheet)の第3版です。CSS3と略されることが多いです。色やデザインを柔軟に変更することが可能になります。

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

Q&A

解決済

1回答

924閲覧

CSS:grid-auto-rowsだけの指定でなぜ60段になる?

Fujiman

総合スコア41

CSS3

CSS(Cascading Style Sheet)の第3版です。CSS3と略されることが多いです。色やデザインを柔軟に変更することが可能になります。

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

0グッド

0クリップ

投稿2021/10/27 01:26

編集2021/10/27 01:48

ここの内容を確認していて
どうも理解できないところがあり教えて下さい。

グリッド用のコンテナのCSSが以下のようになっております。
row関係の指定は”grid-auto-rows: 1fr;”だけです。

当初、思ったのは、列が3列指定になっているので、これだと
3セルごとにrowができ、このサンプルだと8要素あるので
3段だけのグリッドになるのでは?
というものでしたが、実際には”60”段になっています。

CSS

1.container { 2 display: grid; 3 grid-template-columns: repeat(3, 1fr); 4 grid-auto-rows: 1fr; 5 grid-gap: 1em; 6 max-width: 1440px; 7 margin: 0 auto; 8}

HTML

1<div class="container"> 2 <div class="item"></div> 3 <div class="item"></div> 4 <div class="item"></div> 5 <div class="item"></div> 6 <div class="item"></div> 7 <div class="item"></div> 8 <div class="item"></div> 9 <div class="item"></div> 10</div> 11 12<div class="text-box"> 13 <span class="text">Stan Lee</span> 14 <span class="text">1922-2018</span> 15</div>

SCSS

1/*** Fonts ***/ 2@import url('https://fonts.googleapis.com/css?family=Bangers'); 3 4/*** Box Reset ***/ 5* { 6 box-sizing: border-box; 7} 8 9body { 10 background-color: #e3e3e3; 11} 12 13.container{ 14 display: grid; 15 grid-template-columns: repeat(3, 1fr); 16 grid-auto-rows: 1fr; 17 grid-gap: 1em; 18 max-width: 1440px; 19 margin: 0 auto; 20} 21 22.item{ 23 display: inline-block; 24 min-height: 400px; 25 width: 50%; 26 background-position: center center; 27 background-repeat: no-repeat; 28 background-size: cover; 29} 30 31/*** Images With Color Fallbacks ***/ 32.item:nth-child(1){ 33 background-color: #e74c3c; 34 background-image: url(https://i.pinimg.com/originals/e1/12/f8/e112f875d7f05db887f3d7750474fb1a.jpg); 35 background-position: center top; 36} 37 38.item:nth-child(2){ 39 background-color: #3498db; 40 background-image: url(https://static.comicvine.com/uploads/original/8/80103/4528554-amazing_spider-man_vol_3_19.1_ponsor_variant_textless.jpg); 41 background-position: center 35%; 42} 43 44.item:nth-child(3){ 45 background-color: #bdc3c7; 46 background-image: url(http://www.writeups.org/wp-content/uploads/Black-Panther-Avengers-Marvel-Comics-h427.jpg); 47 background-position: center 20%; 48} 49 50.item:nth-child(4){ 51 background-color: #2c3e50; 52 background-image: url(http://designrfix.com/wp-content/uploads/2010/05/The-incredible-hulk-art-12.jpg); 53} 54 55.item:nth-child(5){ 56 background-color: #2c3e50; 57 background-image: url(http://image.noelshack.com/fichiers/2018/46/1/1542053976-stanleefol5.png); 58 background-position: center 20px; 59} 60 61.item:nth-child(6){ 62 background-color: #27ae60; 63 background-image: url(http://cdn.collider.com/wp-content/uploads/2015/01/fantastic-four-comic-2.jpg); 64 background-position: 50% 25%; 65} 66 67.item:nth-child(7){ 68 background-color: #f1c40f; 69 background-image: url(https://nerdeux.files.wordpress.com/2011/09/rogues-thor-01.jpg); 70 background-position: left 27%; 71} 72 73.item:nth-child(8){ 74 background-color: #2980b9; 75 background-image: url(https://2.bp.blogspot.com/-YSoMZR-S8CU/VRhKBl7HsZI/AAAAAAAAQqs/_s8iKmBMCUs/s1600/x-men-1-cover.jpg); 76 background-position: center 22%; 77} 78 79/*** Grid Set Up ***/ 80@supports (display:grid){ 81 .item{ 82 width: auto; 83 min-height: 0; 84 } 85 86 .item:nth-child(1){ 87 grid-column: 1 / span 1; 88 grid-row: 1 / 20; 89 -webkit-clip-path: polygon(0 0, 80% 0, 100% 76.5%, 0 100%); 90 clip-path: polygon(0 0, 80% 0, 100% 76.5%, 0 100%); 91 margin-bottom: -93px; 92 } 93 94 .item:nth-child(2){ 95 grid-column: 2 / span 1; 96 grid-row: 1 / 20; 97 -webkit-clip-path: polygon(0 0, 100% 0, 75% 80%, 15.5% 100%); 98 clip-path: polygon(0 0, 100% 0, 75% 80%, 15.5% 100%); 99 margin-left: -21%; 100 margin-right: -5%; 101 } 102 103 .item:nth-child(3){ 104 grid-column: 3 / span 1; 105 grid-row: 1 / 20; 106 -webkit-clip-path: polygon(25% 0, 100% 0, 100% 100%, 0 53%); 107 clip-path: polygon(25% 0, 100% 0, 100% 100%, 0 53%); 108 margin-left: -28%; 109 margin-bottom: -150px; 110 } 111 112 .item:nth-child(4){ 113 grid-column: 1 / span 1; 114 grid-row: 20 / 40; 115 -webkit-clip-path: polygon(0 22.5%, 100% 0, 100% 77.5%, 0 100%); 116 clip-path: polygon(0 22.5%, 100% 0, 100% 77.5%, 0 100%); 117 margin-top: -5px; 118 margin-bottom: -93px; 119 } 120 121 .item:nth-child(5){ 122 grid-column: 2 / span 1; 123 grid-row: 20 / 40; 124 -webkit-clip-path: polygon(0 13%, 74% 0, 100% 9.25%, 100% 100%, 0 100%); 125 clip-path: polygon(0 13%, 74% 0, 100% 9.25%, 100% 82%, 65% 100%,0 82%); 126 margin-top: -67px; 127 margin-left: -1%; 128 margin-bottom: -86px; 129 } 130 131 .item:nth-child(6){ 132 grid-column: 3 / span 1; 133 grid-row: 20 / 40; 134 -webkit-clip-path: polygon(0 0, 100% 34.5%, 100% 100%, 0 68.5%) ; 135 clip-path: polygon(0 0, 100% 34.5%, 100% 100%, 0 68.5%); 136 margin-left: -1%; 137 margin-top: -20px; 138 margin-bottom: -150px; 139 } 140 141 .item:nth-child(7){ 142 grid-column: 1 / 3; 143 grid-row: 40 / 60; 144 -webkit-clip-path: polygon(0 30%, 49% 0, 75% 38%, 34% 100%, 0 100%); 145 clip-path: polygon(0 30%, 49% 0, 82% 27%, 34% 100%, 0 100%); 146 margin-top: -7px; 147 } 148 149 .item:nth-child(8){ 150 grid-column: 2 / span 2; 151 grid-row: 40 / 60; 152 -webkit-clip-path: polygon(0 100%, 57% 0, 100% 48%, 100% 100%, 0 100%); 153 clip-path: polygon(0 100%, 57% 0, 100% 48%, 100% 100%, 0 100%); 154 margin-left: -15%; 155 margin-top: -7px; 156 } 157} 158 159/*** Floating Text ***/ 160.text-box{ 161 position: absolute; 162 top: 560px; 163 margin-left: auto; 164 margin-right: auto; 165 left: 0; 166 right: 0; 167} 168 169.text{ 170 display: block; 171 text-align: center; 172 color: whitesmoke; 173 text-shadow: 0px 3px 15px #000; 174 font-family: 'Bangers', cursive; 175 font-size: 3.5vmax; 176}

grid-auto-rowsはgrid-template-rowsの指定がない場合、
または、それを超えたところにセルがある場合の高さを指定するプロパティーと
理解しています。

なのでこの指定だけで、なぜ60段なのか?
60という数字はどこから来ているのか?
という点について教えて下さい

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hatena19

2021/10/27 01:37

60段とは、60行という意味ですか。 状況を再現できるコードをHTMLも含めて提示てください。 containerクラスを持つdiv要素内にdiv要素を8個入れて確認してみましたが、提示のCSSだと3行になりました。
Lhankor_Mhy

2021/10/27 01:38

HTMLをご提示ください。 とりあえず、適当なHTMLで試してみましたが問題が再現しませんでしたので、ご提示いただいていない部分に原因があると思われます。
Fujiman

2021/10/27 01:49

質問が不完全ですみません、HTMLとフルのSCSSを追加しました
Fujiman

2021/10/27 01:51

また60段という表現もすみません。60行です
guest

回答1

0

ベストアンサー

.item

grid-row: 1 / 20;

grid-row: 20 / 40;

grid-row: 40 / 60;

を設定しているからです。
40 / 60 というのは、40行目から60行目までに配置するいう意味なので、
60行必要になります。

投稿2021/10/27 01:56

hatena19

総合スコア33795

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Fujiman

2021/10/27 02:17 編集

ありがとうございます。 ソウナンですか! 各アイテムの位置指定は出来上がったグリッドラインで行うもので まだできてもいないライン名(や番号)で指定するものではないと 思い込んでいました。 ということはアイテム側からグリッドラインを 生成することも可能ということになりますね。 すごく勉強になりました
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問