向CSS表添加样式

I'm echoing data out of my database into a <table>, however I'm trying to add a gradient line under each output, to show in-between each <tr> output row. But I can't get the CSS right on the <tr>.

I've managed to put together the design I want on a <hr> here: http://jsfiddle.net/ghrw3k8e/.

But I want it in-between my table rows (not columns).

My PHP output data:

echo " <tr> 
<td align='center'>".$1." </td> 
<td align='center'>".$2."</td> 
<td align='center'>".$3."</td>
 </tr> ";

Just use pseudo-elements. You will have to put that "border" on one <td> of each <tr>, so its width should be equal to 100 × number_of_columns % if they are all the same width:

table {
  width: 100%;
  border-collapse: collapse; 
}

td {
  position:relative;   
  width: 33.333333%;
  border: 1px solid transparent;
  text-align:center;
}

tr:not(:last-child) > td:first-child::after {
  content:"";
  position:absolute;
  bottom:-1px;
  left:0;
  height: 1px;
  width:300%;
  background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(176,0,0,.8), rgba(0,0,0,0));
  background-image:    -moz-linear-gradient(left, rgba(0,0,0,0), rgba(176,0,0,.8), rgba(0,0,0,0));
  background-image:     -ms-linear-gradient(left, rgba(0,0,0,0), rgba(176,0,0,.8), rgba(0,0,0,0));
  background-image:      -o-linear-gradient(left, rgba(0,0,0,0), rgba(176,0,0,.8), rgba(0,0,0,0));
}
<table>
  <tr><td>A</td><td>B</td><td>C</td></tr>
  <tr><td>D</td><td>E</td><td>F</td></tr>
  <tr><td>G</td><td>H</td><td>I</td></tr>
</table>

Although it may seem more logical to have it on the <tr>, it won't get positioned correctly, as you can read from the spec: http://www.w3.org/TR/CSS21/visuren.html#propdef-position

The effect of 'position:relative' on table-row-group, table-header-group, table-footer-group, table-row, table-column-group, table-column, table-cell, and table-caption elements is undefined.

Here's the incorrect code. You can see that the ::after element is positioned at the very bottom of the page:

table {
  width: 100%;
  border-collapse: collapse;
}


tr{
  position:relative;    
}

td {
  width: 33.333333%;
  border: 1px solid transparent;
  text-align: center;
}


tr:not(:last-child)::after {
  content:"";
  position:absolute;
  bottom:-1px;
  left:0;
  height: 1px;
  width:300%;
  background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(176,0,0,.8), rgba(0,0,0,0));
  background-image:    -moz-linear-gradient(left, rgba(0,0,0,0), rgba(176,0,0,.8), rgba(0,0,0,0));
  background-image:     -ms-linear-gradient(left, rgba(0,0,0,0), rgba(176,0,0,.8), rgba(0,0,0,0));
  background-image:      -o-linear-gradient(left, rgba(0,0,0,0), rgba(176,0,0,.8), rgba(0,0,0,0));
}
<table>
  <tr><td>A</td><td>B</td><td>C</td></tr>
  <tr><td>D</td><td>E</td><td>F</td></tr>
  <tr><td>G</td><td>H</td><td>I</td></tr>
</table>

</div>

You can insert an extra row for each line.

hr.soften {
  height: 1px;
  background-image: -webkit-linear-gradient(left, rgba(0, 0, 0, 0), rgba(176, 0, 0, .8), rgba(0, 0, 0, 0));
  background-image: -moz-linear-gradient(left, rgba(0, 0, 0, 0), rgba(176, 0, 0, .8), rgba(0, 0, 0, 0));
  background-image: -ms-linear-gradient(left, rgba(0, 0, 0, 0), rgba(176, 0, 0, .8), rgba(0, 0, 0, 0));
  background-image: -o-linear-gradient(left, rgba(0, 0, 0, 0), rgba(176, 0, 0, .8), rgba(0, 0, 0, 0));
  border: 0;
}
td {
  width: 200px;
}
<table>
  <tr>
    <td>A</td>
    <td>B</td>
  </tr>
  <tr>
    <td>
      <hr class="soften" />
    </td>
  </tr>
  <tr>
    <td>A</td>
    <td>B</td>
  </tr>
  <tr>
    <td>
      <hr class="soften" />
    </td>
  </tr>
  <tr>
    <td>A</td>
    <td>B</td>
  </tr>
</table>

</div>