如何在 3 列网格设置中拉伸中间列

How to stretch middle column in a 3 column grid setup

我正在尝试设置一个单行三列“grid”系统的header。如:

* {box-sizing: border-box;}

.wrapper {
    border: 2px solid #f76707;
    border-radius: 5px;
    background-color: #fff4e6;
}

.wrapper > div {
    border: 2px solid #ffa94d;
    border-radius: 5px;
    background-color: #ffd8a8;
    padding: 1em;
    color: #d9480f;
}
.wrapper {
  display: grid;
  grid-template-columns: 100px,1fr,100px;
  grid-template-rows: 1fr;

  grid-template-areas: "a b c";

}
.item1 {
  grid-area: a;
  justify-self:start;
}
.item2 {
  grid-area: b;
  justify-self:stretch;
}
.item3 {
  grid-area: c;
  justify-self:end;
}
<div class="wrapper">
  <div class="item1">Item 1</div>
  <div class="item2">Item 2</div>
  <div class="item3">Item 3</div>
</div>

但是中间的列只会居中而不是拉伸。 这是 fiddle https://jsfiddle.net/mmo7534/pnxtys79/2/

我怎样才能让它伸展?

从您的 grid-template-columns 值中删除逗号,这样您就不必担心单个项目的样式:

* {
  box-sizing: border-box;
}

.wrapper {
  border: 2px solid #f76707;
  border-radius: 5px;
  background-color: #fff4e6;
  display: grid;
  grid-template-columns: 100px 1fr 100px;
}

.wrapper>div {
  border: 2px solid #ffa94d;
  border-radius: 5px;
  background-color: #ffd8a8;
  padding: 1em;
  color: #d9480f;
}
<div class="wrapper">
  <div class="item1">Item 1</div>
  <div class="item2">Item 2</div>
  <div class="item3">Item 3</div>

</div>

* {box-sizing: border-box;}

.wrapper {
    border: 2px solid #f76707;
    border-radius: 5px;
    background-color: #fff4e6;
}

.wrapper > div {
    border: 2px solid #ffa94d;
    border-radius: 5px;
    background-color: #ffd8a8;
    padding: 1em;
    color: #d9480f;
}
.wrapper {
  display: grid;
  grid-template-columns: 100px 1fr 100px; /* there are no commas. */
  grid-template-rows: 1fr;

  grid-template-areas: "a b c";

}

.item2 {
  grid-area: b;
  justify-self:stretch;
} /* Item1 and Item2 automatically will be aligned at start and end. */

只需从您的网格模板列值中删除逗号即可。

 grid-template-columns: 100px 1fr 100px;

https://jsfiddle.net/3cv6ypq5/