没有条纹/边框的Bootstrap表

Rom*_*ain 179 html css twitter-bootstrap

我在使用Bootstrap时遇到了CSS问题.我也使用Angular JS和Angular UI.bootstrap(这可能是问题的一部分).

我正在建立一个在表格中显示数据的网站.有时,数据包含我必须在表格中显示的对象.因此,我希望将无边框表放在普通表中,同时保持无边框表的内部分隔线.

但似乎即使我特意说不在桌子上显示边框,它也是强制的:

HTML:

<table class='table borderless'>
Run Code Online (Sandbox Code Playgroud)

CSS:

.borderless table {
    border-top-style: none;
    border-left-style: none;
    border-right-style: none;
    border-bottom-style: none;
}
Run Code Online (Sandbox Code Playgroud)

所以在这里,我想要的只是内部边界.

Dav*_*ore 331

使用Bootstrap 3.2.0我遇到了Brett Henderson解决方案的问题(边界始终存在),所以我改进了它:

HTML

<table class="table table-borderless">
Run Code Online (Sandbox Code Playgroud)

CSS

.table-borderless > tbody > tr > td,
.table-borderless > tbody > tr > th,
.table-borderless > tfoot > tr > td,
.table-borderless > tfoot > tr > th,
.table-borderless > thead > tr > td,
.table-borderless > thead > tr > th {
    border: none;
}
Run Code Online (Sandbox Code Playgroud)

  • 不要忘记正文中的`th`元素:`.borderless tbody tr th`(在[examples]中使用(http://getbootstrap.com/css/#tables-example)) (2认同)
  • @DavidePastore如果这只是表,可以用`.table -`作为前缀,因为Bootstrap 3可以用于其他表相关的类(例如`table-striped`等).所以名字将是`table-borderless`. (2认同)
  • 很高兴去v3.3 (2认同)

小智 265

边框样式设置在td元素上.

HTML:

<table class='table borderless'>
Run Code Online (Sandbox Code Playgroud)

CSS:

.borderless td, .borderless th {
    border: none;
}
Run Code Online (Sandbox Code Playgroud)

更新:从Bootstrap 4.1开始,您可以使用.table-borderless删除边框.

https://getbootstrap.com/docs/4.1/content/tables/#borderless-table

  • 我不得不添加border:none!important; 使它工作. (40认同)
  • 注意:你还应该添加`.borderless th`,因为Bootstrap样式也适用于`<th>`. (11认同)
  • 如果您使用的是Bootstrap 3,请查看我的[answer](http://stackoverflow.com/a/24830641/1992780). (11认同)
  • 对不起,这不适用于Bootstrap 3.3 (3认同)
  • 它不够具体,不起作用. (2认同)

Sam*_*nes 24

与其他类似,但更具体:

    table.borderless td,table.borderless th{
     border: none !important;
}
Run Code Online (Sandbox Code Playgroud)

  • !important对我有用.(使用Bootstrap 3) (4认同)

Mar*_*ean 17

不要将.table类添加到<table>标记中.从上的Bootstrap文档:

对于基本样式 - 轻型填充和仅水平分隔 -将基类添加.table到任何基础<table>.它可能看起来超级冗余,但考虑到其他插件(如日历和日期选择器)的广泛使用,我们选择隔离自定义表格样式.

  • 这很好用,我只是使用'table-condensed'和其他没有'table'类的变种,并且摆脱了边界.很棒的提示,因为文档把我扔了一点. (6认同)
  • 我建议在Chrome中使用Web Inspector,然后查看应用任何边框的位置,因为默认情况下,当使用Bootstrap与其他组件(如日期选择器等)进行互操作时,表格没有边框. (2认同)

Max*_*Max 8

从Bootstrap v4.1开始,您可以添加table-borderless到您的表中,请参阅官方文档:

<table class='table table-borderless'>
Run Code Online (Sandbox Code Playgroud)


S K*_*mar 8

使用 npm 或 cdn 链接安装 bootstrap

<table class="table table-borderless">
<thead>
<tr>
  <th scope="col">#</th>
  <th scope="col">First</th>
  <th scope="col">Last</th>
  <th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
  <th scope="row">1</th>
  <td>Mark</td>
  <td>Otto</td>
  <td>@mdo</td>
</tr>
<tr>
  <th scope="row">2</th>
  <td>Jacob</td>
  <td>Thornton</td>
  <td>@fat</td>
  </tr>
  <tr>
  <th scope="row">3</th>
    <td colspan="2">Larry the Bird</td>
    <td>@twitter</td>
   </tr>
 </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

通过此链接获取参考


Dan*_*eng 5

在我的CSS中:

.borderless tr td {
    border: none !important;
    padding: 0px !important;
}
Run Code Online (Sandbox Code Playgroud)

在我的指令中:

<table class='table borderless'>
    <tr class='borderless' ....>
Run Code Online (Sandbox Code Playgroud)

我没有为td元素添加'无边界'.

经过测试,确实有效!所有边框和衬垫都被完全剥离.


she*_*lco 5

我像 Davide Pastore 一样扩展了 Bootstrap 表格样式,但使用这种方法,样式也适用于所有子表格,而它们不适用于页脚。

更好的解决方案是模仿核心 Bootstrap 表格样式,但使用您的新类:

.table-borderless>thead>tr>th
.table-borderless>thead>tr>td
.table-borderless>tbody>tr>th
.table-borderless>tbody>tr>td
.table-borderless>tfoot>tr>th
.table-borderless>tfoot>tr>td {
    border: none;
}
Run Code Online (Sandbox Code Playgroud)

然后当你<table class='table table-borderless'>只使用带有类的特定表时,树中的任何表都不会被加边框。