代码之家  ›  专栏  ›  技术社区  ›  Ousama

在html表格中显示行而不是空单元格

  •  0
  • Ousama  · 技术社区  · 4 年前

    我需要在html表的空单元格中显示类似下图的内容(我使用的是bootstrap4.3.1)

    enter image description here

    <!DOCTYPE html>
    <html>
    <head>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
    </head>
    <body>
    
    <table class="table table-bordered">
      <tr>
        <td>Peter</td>
        <td>Griffin</td>
      </tr>
      <tr>
        <td>Lois</td>
        <td></td>
      </tr>
    </table>
    
    </body>
    </html>

    预期结果:

    enter image description here

    先谢谢你。

    2 回复  |  直到 4 年前
        1
  •  3
  •   Temani Afif    4 年前

    使用渐变背景与 :empty

    td:empty {
      background:repeating-linear-gradient(-45deg, transparent 0 3px,#000 0 6px);
    }
    <!DOCTYPE html>
    <html>
    <head>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
    </head>
    <body>
    
    <table class="table table-bordered">
      <tr>
        <td>Peter</td>
        <td>Griffin</td>
      </tr>
      <tr>
        <td>Lois</td>
        <td></td>
      </tr>
    </table>
    
    </body>
    </html>

    td:empty {
      background:
       url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="2 0 2 3"><line x1="0" y1="5" x2="4" y2="-1" stroke="black"></line><line x1="2" y1="5" x2="6" y2="-1" stroke="black"></line></svg>') 0 0/8px 12px;
    }
    <!DOCTYPE html>
    <html>
    <头部>
    </head>
    <车身>
    
    <table class=“table bordered”>
    <td>彼得</td>
    <td>格里芬</td>
    </tr>
    <tr>
    <td>意向书</td>
    </tr>
    
    </body>
    </html>
        2
  •  1
  •   Lalji Tadhani    4 年前

    :empty

    td:empty{
      background:red;
    }
    <!DOCTYPE html>
    <html>
    <head>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
    </head>
    <body>
    
    <table class="table table-bordered">
      <tr>
        <td>Peter</td>
        <td>Griffin</td>
      </tr>
      <tr>
        <td>Lois</td>
        <td></td>
      </tr>
      <tr>
        <td></td>
        <td>Lois</td>
      </tr>
    </table>
    
    </body>
    </html>