小编San*_*lin的帖子

如何计算()网格模板中的行数?

我想计算网格模板中使用的行数calc(),但是尝试repeat使用除法计数是不行的:

.grid {
  display: grid;
  grid-gap: 10px;
  grid-template-columns: 1fr;
  margin-bottom: 10px;
  background: rgba(0, 0, 0, 0.2);
}

.grid>div {
  background: tomato;
  width: 20px;
  text-align: center;
  margin: auto;
}

.grid.no-calc {
  grid-template-rows: repeat(3, 30px);
}

.grid.addition {
  grid-template-rows: repeat(calc(1 + 2), 30px);
}

.grid.subtraction {
  grid-template-rows: repeat(calc(4 - 1), 30px);
}

.grid.multiplication {
  grid-template-rows: repeat(calc(3 * 1), 30px);
}

.grid.division {
  grid-template-rows: repeat(calc(6 / 2), 30px);
}
Run Code Online (Sandbox Code Playgroud)
<p>Top 4 have their row heights set correctly</p>

<div class="grid …
Run Code Online (Sandbox Code Playgroud)

html css css3 css-grid css-calc

5
推荐指数
1
解决办法
134
查看次数

标签 统计

css ×1

css-calc ×1

css-grid ×1

css3 ×1

html ×1