【问题标题】:Grid column not stretching across entire row [duplicate]网格列没有延伸到整行[重复]
【发布时间】:2018-01-27 13:30:18
【问题描述】:

我的 html 正文中有以下 html

<div class="wrapper">
  <div class="box1">One</div>
  <div class="box2">Two</div>
  <div class="box3">Three</div>
</div>

使用 this 作为内联样式

.wrapper { 
  display: grid; 
  grid-template-columns: 1fr 7fr;
} 
.box1 { 
  grid-column: 1 / 2;
  grid-row: 1 / 1; 
  background-color: red;
}
.box2 { 
  grid-column: 1 / 1; 
  grid-row: 2 / 2; 
  background-color: blue;
}
.box3 { 
  grid-column: 2 / 2; 
  grid-row: 2 / 2; 
  background-color: green;
}

这可能不理解规范,但任何人都可以解释为什么我必须从

更改 box1
grid-column: 1 / 2;

grid-column: 1 / 3;

为了使 div1 跨越两列? 见https://jsfiddle.net/vyx4jacm/

【问题讨论】:

标签: html css css-grid


【解决方案1】:

grid-columngrid-column-startgrid-column-end 的缩写。 grid-column 的第二个数字是您的结束网格线。

由于您只指定了 2 列(通过grid-template-columns),这意味着将有 2 列轨道和 3 列网格线。因此,要跨越所有,您需要 grid-column-end 值为 3,而不是 2。

【讨论】:

  • 啊,那是我误会的信息,非常感谢!
猜你喜欢
  • 2012-02-26
  • 1970-01-01
  • 1970-01-01
  • 2013-06-08
  • 2019-06-10
  • 1970-01-01
  • 1970-01-01
  • 2019-03-15
  • 1970-01-01
相关资源
最近更新 更多