A better alternative than   for showing empty HTML table cells?

前端 未结 2 1855
再見小時候
再見小時候 2020-12-09 16:46

It\'s a classic problem - when you have an empty table cell the browser doesn\'t render borders around it. There are also two well-known workarounds. One is to place an

2条回答
  •  借酒劲吻你
    2020-12-09 17:21

    You can show the cells with this CSS code. I successfully tested it in Safari and Firefox. I guess it works in other browsers as well.

    table {
      width: 100%;
      border: 0;
      empty-cells: show;
    }
    td {
      border: 1px solid grey;
    }
    td:empty:after {
      content: '.';
      color: transparent;
      visibility: hidden;
    }
    /* alternate background */
    
    tr:nth-child(odd) td {
      background: rgba(0, 0, 0, 0.2);
    }
    tr:nth-child(even) td {
      background: rgba(0, 0, 0, 0.1);
    }
    Row 1
    Row 3

提交回复
热议问题