我在Chrome和Firefox中观察到此代码的不同行为: HTML:
.container{
display: grid;
grid-template-columns: 40px 50px 500px 50px 40px;
grid-template-rows: 25% 100px auto;
background-color: violet;
}
<div class="container">
<div class="item item-1">1</div>
<div class="item item-2">2</div>
<div class="item item-3">3</div>
<div class="item item-4">4</div>
<div class="item item-5">5</div>
<div class="item item-6">6</div>
<div class="item item-7">7</div>
<div class="item item-8">8</div>
<div class="item item-9">9</div>
<div class="item item-10">10</div>
<div class="item item-11">11</div>
<div class="item item-12">12</div>
</div>
有任何想法为什么会这样吗?
答案 0 :(得分:0)
如果未为“ .container”网格指定高度,则百分比将被视为自动。我认为这就是这种行为的原因。
.container{
display: grid;
grid-template-columns: 40px 50px 500px 50px 40px;
grid-template-rows: auto 100px auto;
background-color: violet;
}
<div class="container">
<div class="item item-1">1</div>
<div class="item item-2">2</div>
<div class="item item-3">3</div>
<div class="item item-4">4</div>
<div class="item item-5">5</div>
<div class="item item-6">6</div>
<div class="item item-7">7</div>
<div class="item item-8">8</div>
<div class="item item-9">9</div>
<div class="item item-10">10</div>
<div class="item item-11">11</div>
<div class="item item-12">12</div>
</div>