如何在表的某些列之间添加间距?

Tim*_*Guo 5 html css html-table spacing twitter-bootstrap

我想做一个这样的表: 意

C和D,D和E以及F和G之间应该有间距.但是任何其他列之间不应该有任何空格,例如A和B.

这就是我目前拥有的: 当前

JSFiddle:https://jsfiddle.net/e33cbkh3/1/

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');

thead {
background: orange;
}

th, td {
text-align: center;
border: none !important;
}
Run Code Online (Sandbox Code Playgroud)
<table class="table table-striped table-bordered table-hover">
  <thead>
    <tr>
      <th colspan="3"></th>
      <th></th>
      <th colspan="2"> XYZ </th>
      <th></th>
    </tr>
    <tr>
      <th>A</th>
      <th>B</th>
      <th>C</th>
      <th>D</th>
      <th>E</th>
      <th>F</th>
      <th>G</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>2</td>
      <td>3</td>
      <td>4</td>
      <td>5</td>
      <td>6</td>
      <td>7</td>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

God*_*win 4

最简单的解决方案是在表中包含一些额外的空列:

超文本标记语言

<table class="table">
  <thead>
    <tr>
      <th colspan="3"></th>
      <th class="space"></th>
      <th></th>
      <th class="space"></th>
      <th colspan="2"> XYZ </th>
      <th class="space"></th>
      <th></th>
    </tr>
    <tr>
      <th>A</th>
      <th>B</th>
      <th>C</th>
      <th class="space"></th>
      <th>D</th>
      <th class="space"></th>
      <th>E</th>
      <th>F</th>
      <th class="space"></th>
      <th>G</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>2</td>
      <td>3</td>
      <td class="space"></td>
      <td>4</td>
      <td class="space"></td>
      <td>5</td>
      <td>6</td>
      <td class="space"></td>
      <td>7</td>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

CSS

/* make the cells appear to be empty */
.space {
  background: none;
  /* make the width small, but setting it to 0 will actual default to the same width as other cells */
  width: 0.1rem;
}
Run Code Online (Sandbox Code Playgroud)

您还需要将thead背景颜色移动到th元素:

th {
  background: orange;
}
Run Code Online (Sandbox Code Playgroud)

JSFiddle: https: //jsfiddle.net/L43weozq/