表轮廓边框和列边框仅在Bootstrap中

时间:2018-09-01 06:16:43

标签: html css html-table

我希望像下面这样的表,只有outline_border(?)和column border出现在表中,但是当我尝试在行中使用深色的淡入淡出边框时:

enter image description here

How I achieve so far:

enter image description here

  

如何获得具有轮廓边框和列边框而不是连续的表格。我使用了引导CSS。

如果我使用表类table-borderless,则行行和除outline-border之外的所有行都消失了,但是我希望列边框位于表中

I try like this questions

请在下面播放:

table {
    border:1px solid black;
    border-collapse: collapse;
}
table tr {
  border-left: 1px solid #000;
  border-right: 1px solid #000;
}

table td {
    border-left: 1px solid #000;
    border-right: 1px solid #000;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"/>

<table class="table table-small">
  <thead>
    <tr>
      <th>#</th>
      <th>Name</th>
      <th>Col1</th>
      <th>Col2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
  </tbody>
</table>

3 个答案:

答案 0 :(得分:1)

问题在于引导程序会覆盖部分定义。为避免这种情况,您可以制作某些CSS !important

编辑:已删除表格单元格之间的水平线。

.table {
  border: 1px solid black;
}

.table thead th {
  border-top: 1px solid #000!important;
  border-bottom: 1px solid #000!important;
  border-left: 1px solid #000;
  border-right: 1px solid #000;
}

.table td {
  border-left: 1px solid #000;
  border-right: 1px solid #000;
  border-top: none!important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />

<table class="table table-small">
  <thead>
    <tr>
      <th>#</th>
      <th>Name</th>
      <th>Col1</th>
      <th>Col2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
  </tbody>
</table>

答案 1 :(得分:0)

我对以上评论的问题是,我可以实现下面想要的功能,但是我必须在各处使用内联CSS。有没有更好的方法可以使用,而不仅仅是内联CSS

.table {
  border: 1px solid black;
}

.table thead th {
  border-top: 1px solid #000!important;
  border-bottom: 1px solid #000!important;
  border-left: 1px solid #000;
  border-right: 1px solid #000;
}

.table td {
  border-left: 1px solid #000;
  border-right: 1px solid #000;
  border-top: none!important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />

<table class="table table-small">
  <thead>
    <tr>
      <th>#</th>
      <th>Name</th>
      <th>Col1</th>
      <th>Col2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
    <tr>
      <td>1</td>
      <td>sub-total</td>
      <td style="border-bottom: 1px solid #000;border-top: 1px solid #000!important;">123</td>
      <td style="border-bottom: 1px solid #000;border-top: 1px solid #000!important">456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr>
      <td>2</td>
      <td>name2</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
    <tr>
      <td>1</td>
      <td>name</td>
      <td>123</td>
      <td>456</td>
    </tr>
    <tr style="border-top: 1px solid #000!important">
      <td>##</td>
      <td>Total</td>
      <td>xyz</td>
      <td>abc</td>
    </tr>
  </tbody>
</table>

答案 2 :(得分:0)

只有在我们的 head 标签中添加这些样式才能做到这一点

.invoice-table {
        border: 1px solid black;
    }

    .invoice-table thead th {
        border: 1px solid #000!important;

    }

    .invoice-table td {
        border: 1px solid #000;

    }

导入:为每个 tr 设置一行,我们可以简单地添加到

<tr style="border-top: 1px solid #000!important">