CSS表格行和单元格宽度

时间:2018-05-28 15:29:15

标签: css css-tables

这里我有一个非常棘手的问题。 ) 如何制作宽度为100%的第三个单元格,并从第一行开始单独生成底行?



/* Table */

* {
  box-sizing: border-box;
}

.table {
  display: table;
  width: 300px;
  margin-bottom: 1rem;
  border: 2px solid rgba(255, 0, 0, .40);
}

/* Grid */

.row {
  display: table-row;
}

.cell {
  display: table-cell;
}

/* Grid Width */

.cell-1 {
  width: 50%;
}

.cell-2 {
  width: 100%;
}

/* Decoration */

body {
  font-family: monospace;
  font-size: 15px;
}

.cell {
  line-height: 3;
  text-align: center;
  background-color: rgba(255, 0, 0, .3);
  border: 1px solid white;
}

<div class="table">
  <div class="row">
      <div class="cell cell-1">1</div>
      <div class="cell cell-1">2</div>
  </div>
  <div class="row">
      <div class="cell cell-3">3</div>
  </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

我使用Table Tag重写你的程序。该计划如下。

&#13;
&#13;
* {
  box-sizing: border-box;
}
table {
  display: table;
  width: 300px;
  margin-bottom: 1rem;
  border: 2px solid rgba(255, 0, 0, .40);
}

/* Grid */

tr {
  display: table-row;
}

td {
  display: table-cell;
}

/* Decoration */

body {
  font-family: monospace;
  font-size: 15px;
}

td {
  line-height: 3;
  text-align: center;
  background-color: rgba(255, 0, 0, .3);
  border: 1px solid white;
}
&#13;
<table>
  <tr>
    <td>1</td>
    <td>2</td>
  </tr>
  <tr>
    <td colspan="2">3</td>
  </tr>
</table>
&#13;
&#13;
&#13;