Bootstrap CSS - 更改 Table 边框颜色

Boostrap CSS - Change Table Border Colors

如何使用 Bootstrap CSS 更改 HTML Table 中的列边框?

这是我到目前为止去过的地方:

Boostrap 预定义 Table

table 位于超大屏幕内,我想更改 table 边框和线条,以便更容易区分。这就是我到目前为止所做的。

如您所见,列之间的 table 行保持不变。如何改变?

任何其他关于改进 Table 外观的建议都非常感谢

table.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>
<div class="container">
    <div class="jumbotron">
        <h2>Employees</h2>
        <div class="row">
            <div class="col-md-12">
                <div class="pull-right">
                    <button class="btn btn-primary" data-toggle="modal" data-target="#add_new_record_modal">Add New Record</button>
                </div>
            </div>
        </div>
        <br>
        <table class="table table-bordered">
            <thead>
            <tr>
                <th>Firstname</th>
                <th>Lastname</th>
                <th>Email</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>John</td>
                <td>Doe</td>
                <td>john@example.com</td>
            </tr>
            <tr>
                <td>Mary</td>
                <td>Moe</td>
                <td>mary@example.com</td>
            </tr>
            <tr>
                <td>July</td>
                <td>Dooley</td>
                <td>july@example.com</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

</body>

table.css

.jumbotron{
    margin-top:250px
}

tr {
    border: 3px solid gray;
}

代码现在在 JsFiddle

border left & right 添加到 td & th:

table td ,table th{
    border-left: 3px solid gray !important;
    border-right: 3px solid gray !important;
}


table td:first-child {
    border-left: none;
}

table td:last-child {
    border-right: none;
}

试试这个

.jumbotron .table-bordered tbody tr {
  border: 3px solid gray;
}

.jumbotron .table-bordered tbody tr td {
  border: 3px solid gray;
}

.jumbotron .table-bordered tbody tr {
  border: 3px solid gray;
}

.jumbotron .table-bordered thead tr {
  border: 3px solid gray;
}

.jumbotron .table-bordered thead tr th {
  border: 3px solid gray;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>
  <div class="container">
    <div class="jumbotron">
      <h2>Employees</h2>
      <div class="row">
        <div class="col-md-12">
          <div class="pull-right">
            <button class="btn btn-primary" data-toggle="modal" data-target="#add_new_record_modal">Add New Record</button>
          </div>
        </div>
      </div>
      <br>
      <table class="table table-bordered">
        <thead>
          <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Email</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>John</td>
            <td>Doe</td>
            <td>john@example.com</td>
          </tr>
          <tr>
            <td>Mary</td>
            <td>Moe</td>
            <td>mary@example.com</td>
          </tr>
          <tr>
            <td>July</td>
            <td>Dooley</td>
            <td>july@example.com</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>

</body>

.table-bordered td, .table-bordered th {
   border: 3px solid gray !important;
}

您无法设置列边框的原因是 CSS specificity。 您的规则正在被更具体的规则覆盖,在您的情况下,<td> 最具体的规则是由 Bootstrap 设置的 .table-bordered>tbody>tr>td。 对于如何处理这种情况,您有两种选择:

使用更具体的规则

编写将覆盖 Bootstrap 设置的规则,例如:

HTML

<table id="employees-table" class="table table-bordered">
  ...
</table> 

CSS

#employees-table td,
#employees-table th
{
  border: 3px solid gray;
}

使用 !important 异常

使用 !important 被认为是一种不好的做法,但对于您的情况,这可能是最 quickest/easiest 的解决方案:

table td,
table th
{
  border: 3px solid gray !important;
}