【问题标题】:HTML CSS Table border color issue for row行的HTML CSS表格边框颜色问题
【发布时间】:2020-10-05 18:16:46
【问题描述】:

.table-content {
    overflow-x: auto;
}

.table-content table tr th {
    font-weight: 500;
}

table {
    border-collapse: collapse;
    width: 100%;
}
tr {
        border-bottom: 1px solid rgba(38, 46, 46, 0.2);
}
th {
    background: rgb(0 0 0 / 15%);
    padding: 15px;
       border-bottom: 1px solid rgba(38, 46, 46, 0.2);
    color: $dark-text;
    font-size: 0.875rem;
    font-weight: 600;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

td {
    padding: 15px;
    font-size: 1rem;
}
  <div class="table-content">
            <table>
                <tr>
                    <th rowspan="1"></th>
                    <th>Product</th>
                    <th>Rate</th>
                    <th>Discount</th>
                    <th>Quantity</th>
                    <th rowspan="1"></th>
                    <th>Amount</th>
                </tr>
                    <tr>
                        <td>
                            <span>
                                <img src="/assets/images/img-placeholder.svg" >
                            </span>
                        </td>
                        <td>keychain</td>
                        <td>200</td>
                        <td>20</td>
                        <td>Ordered</td>
                        <td>10</td>
                        <td>20</td>
                    </tr>
                    <tr>
                        <td colspan="4"></td>
                        <td>Invoiced</td>
                        <td>2</td>
                        <td colspan="1"></td>
                    </tr>
                    <tr>
                        <td colspan="4"></td>
                        <td>Shipped</td>
                        <td>1</td>
                        <td colspan="1"></td>
                    </tr>
                    <tr>
                        <td colspan="4"></td>
                        <td>Returned</td>
                        <td>1</td>
                        <td colspan="1"></td>
                    </tr>
            </table>
        </div>

在这种情况下,我想让边框底部颜色与其他边框相同,表格的第一行与其他 tr 具有相同的边框底部颜色属性,但在第一行中,我添加了td 比如 image, rate, discount 所以问题是底部边框颜色比其他 tr 边框要深一些。我怎样才能实现相同的边框颜色..?

【问题讨论】:

    标签: javascript html css angular


    【解决方案1】:

    当您的某些 colspan 为空时,Chrome 或 Opera 可能会发生此错误。 因此,您要么直接选择不透明的灰色,因为它来自不透明。

    您可以使用下面的技巧与 box-shadow。

    tr {
      box-shadow: 0px 1px 0px 0px rgba(38, 46, 46, 0.2);
    }
    

    我还为tr:first-childtr:last-child 自定义属性。保持边框正常,不使用盒子阴影

    演示:

    .table-content {
        overflow-x: auto;
    }
    
    .table-content table tr th {
        font-weight: 500;
    }
    
    table {
        border-collapse: collapse;
        width: 100%;
    }
    tr:first-child, tr:last-child{
       box-shadow: 0px 0px 0px 0px rgba(38, 46, 46, 0.2);
       border-bottom: 1px solid rgba(38, 46, 46, 0.2);
    }
    tr {
      box-shadow: 0px 1px 0px 0px rgba(38, 46, 46, 0.2);
    }
    th {
        background: rgb(0 0 0 / 15%);
        padding: 15px;
           border-bottom: 1px solid rgba(38, 46, 46, 0.2);
        color: $dark-text;
        font-size: 0.875rem;
        font-weight: 600;
        text-align: left;
        text-transform: uppercase;
        white-space: nowrap;
    }
    
    td {
        padding: 15px;
        font-size: 1rem;
    }
    <div class="table-content">
                <table>
                    <tr>
                        <th rowspan="1"></th>
                        <th>Product</th>
                        <th>Rate</th>
                        <th>Discount</th>
                        <th>Quantity</th>
                        <th rowspan="1"></th>
                        <th>Amount</th>
                    </tr>
                        <tr>
                            <td>
                                <span>
                                    <img src="/assets/images/img-placeholder.svg" >
                                </span>
                            </td>
                            <td>keychain</td>
                            <td>200</td>
                            <td>20</td>
                            <td>Ordered</td>
                            <td>10</td>
                            <td>20</td>
                        </tr>
                        <tr>
                            <td colspan="4"></td>
                            <td>Invoiced</td>
                            <td>2</td>
                            <td colspan="1"></td>
                        </tr>
                        <tr>
                            <td colspan="4"></td>
                            <td>Shipped</td>
                            <td>1</td>
                            <td colspan="1"></td>
                        </tr>
                        <tr>
                            <td colspan="4"></td>
                            <td>Returned</td>
                            <td>1</td>
                            <td colspan="1"></td>
                        </tr>
                </table>
            </div>

    【讨论】:

      【解决方案2】:

      我看不出 CSS 有什么问题,但如果你填满整个表格,它应该就没了。

      .table-content {
          overflow-x: auto;
      }
      
      .table-content table tr th {
          font-weight: 500;
      }
      
      table {
          border-collapse: collapse;
          width: 100%;
      }
      tr {
              border-bottom: 1px solid rgba(38, 46, 46, 0.2);
      }
      
      th {
          background: rgb(0 0 0 / 15%);
          padding: 15px;
             border-bottom: 1px solid rgba(38, 46, 46, 0.2);
          color: $dark-text;
          font-size: 0.875rem;
          font-weight: 600;
          text-align: left;
          text-transform: uppercase;
          white-space: nowrap;
      }
      
      td {
          padding: 15px;
          font-size: 1rem;
      }
      <div class="table-content">
                  <table>
                      <tr>
                          <th rowspan="1"></th>
                          <th>Product</th>
                          <th>Rate</th>
                          <th>Discount</th>
                          <th>Quantity</th>
                          <th rowspan="1"></th>
                          <th>Amount</th>
                      </tr>
                          <tr>
                              <td>
                                      <img src="/assets/images/img-placeholder.svg" >
                              </td>
                              <td>keychain</td>
                              <td>200</td>
                              <td>20</td>
                              <td>Ordered</td>
                              <td>10</td>
                              <td>20</td>
                          </tr>
                          <tr>
                              <td>
                                      <img src="/assets/images/img-placeholder.svg" >
                              </td>
                              <td>keychain</td>
                              <td>200</td>
                              <td>20</td>
                              <td>Ordered</td>
                              <td>10</td>
                              <td>20</td>
                          </tr>
                          <tr>
                              <td>
                                      <img src="/assets/images/img-placeholder.svg" >
                              </td>
                              <td>keychain</td>
                              <td>200</td>
                              <td>20</td>
                              <td>Ordered</td>
                              <td>10</td>
                              <td>20</td>
                          </tr>
                          <tr>
                             <td>
                                      <img src="/assets/images/img-placeholder.svg" >
                              </td>
                              <td>keychain</td>
                              <td>200</td>
                              <td>20</td>
                              <td>Ordered</td>
                              <td>10</td>
                              <td>20</td>
                          </tr>
                  </table>
              </div>

      【讨论】:

      • 在 Firefox 中似乎不会发生这种情况。我怀疑这是 Chrome 中的一个错误,与未渲染的单元格有关。空的单元格不会渲染,这就是为什么您经常看到它们充满&amp;nbsp;
      【解决方案3】:

      .table-content {
          overflow-x: auto;
      }
      
      .table-content table tr th {
          font-weight: 500;
      }
      
      table {
          border-collapse: collapse;
          width: 100%;
      }
      tr {
      }
      th {
          background: rgb(0 0 0 / 15%);
          padding: 15px;
             border-bottom: 1px solid rgba(38, 46, 46, 0.2);
          color: $dark-text;
          font-size: 0.875rem;
          font-weight: 600;
          text-align: left;
          text-transform: uppercase;
          white-space: nowrap;
      }
      
      td {
          padding: 15px;
          font-size: 1rem;
              border-bottom: 1px solid #ddd;
      }
      <div class="table-content">
                  <table>
                      <tr>
                          <th rowspan="1"></th>
                          <th>Product</th>
                          <th>Rate</th>
                          <th>Discount</th>
                          <th>Quantity</th>
                          <th rowspan="1"></th>
                          <th>Amount</th>
                      </tr>
                          <tr>
                              <td>
                                  <span>
                                      <img src="/assets/images/img-placeholder.svg" >
                                  </span>
                              </td>
                              <td>keychain</td>
                              <td>200</td>
                              <td>20</td>
                              <td>Ordered</td>
                              <td>10</td>
                              <td>20</td>
                          </tr>
                          <tr>
                              <td colspan="4"></td>
                              <td>Invoiced</td>
                              <td>2</td>
                              <td colspan="1"></td>
                          </tr>
                          <tr>
                              <td colspan="4"></td>
                              <td>Shipped</td>
                              <td>1</td>
                              <td colspan="1"></td>
                          </tr>
                          <tr>
                              <td colspan="4"></td>
                              <td>Returned</td>
                              <td>1</td>
                              <td colspan="1"></td>
                          </tr>
                  </table>
              </div>

      我解决了问题...我认为颜色代码是错误的。

      【讨论】:

        【解决方案4】:

        使用类似的东西

        tr{
        border-bottom: 1px solid silver;
        }
        

        为我工作。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-02-02
          • 2011-12-18
          • 2011-05-05
          • 1970-01-01
          • 2018-01-26
          • 2011-08-18
          • 2013-03-06
          相关资源
          最近更新 更多