CSS3 网格 - 为什么行没有按照 column/row stmt 定位

CSS3 Grid - why the rows are not positioned as per column/row stmt

我正在尝试设计带有 up/OK/down/left/right 按钮的电视遥控器,使用 grid layout. The issue is that the result is unexpected to me. I simply want to define 3 rows and 3 columns with specific position and space equally divided between them. What am I doing wrong? The result 看起来像这样

Up       left   OK
right  down

而不是

         Up
         |
<left----OK---Right-->
         |
        Down

代码

#grid {
display: grid;
grid-template-columns:
    /* 1 */ auto
    /* 2 */ auto
    /* 3 */ auto;

grid-template-rows:
    /* 4 */ auto
    /* 5 */ auto
    /* 6 */ auto;
}

#up { grid-column: 2; grid-row: 1; }
#ok { grid-column: 2; grid-row: 2; }
#down { grid-column: 2; grid-row: 3; }
#left { grid-column: 1; grid-row: 3; }
#right { grid-column: 3; grid-row: 3; }

}

<div id="grid">
  <div class="up">Up</div>
  <div class="left">left</div>
  <div class="ok">OK</div>
  <div class="right">right</div>
  <div class="down">down</div>
</div>

你的主要问题是你已经在你的内部元素上设置了 类,并且是样式 ids

#grid {
display: grid;
grid-template-columns:
    /* 1 */ auto
    /* 2 */ auto
    /* 3 */ auto;

grid-template-rows:
    /* 4 */ auto
    /* 5 */ auto
    /* 6 */ auto;

    width: 200px;
}

#grid div {
    width: 50px;
    height: 50px;
    background-color: lightblue;
    margin: 3px;
}

.up { grid-column: 2; grid-row: 1; }
.ok { grid-column: 2; grid-row: 2; }
.down { grid-column: 2; grid-row: 3; }
.left { grid-column: 1; grid-row: 2; }
.right { grid-column: 3; grid-row: 2; }
<div id="grid">
  <div class="up">Up</div>
  <div class="left">left</div>
  <div class="ok">OK</div>
  <div class="right">right</div>
  <div class="down">down</div>
</div>