HTML Element Style How to - Compare the border separate and border collapse








Question

We would like to know how to compare the border separate and border collapse.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
table {<!--   w w  w . j av a2 s .c  o m-->
  border-spacing: 0px;
}

td {
  border: 1px solid blue;
  background-color: yellow;
  padding: 5px;
}

td.cellRelative {
  position: relative;
}

td.cellRelativeFix {
  background-clip: padding-box;
}

table.tableSeparate {
  border-collapse: separate;
}

table.tableCollapse {
  border-collapse: collapse;
}
</style>
</head>
<body>
  table with border-collapse: separate
  <br />
  <table class="tableSeparate">
    <tbody>
      <tr>
        <td class="cellRelative">position: relative</td>
        <td>position: static</td>
      </tr>
    </tbody>
  </table>
  <br /> table with border-collapse: collapse
  <br />
  <table class="tableCollapse">
    <tbody>
      <tr>
        <td class="cellRelative">position: relative</td>
        <td>position: static</td>
      </tr>
    </tbody>
  </table>

</body>
</html>

The code above is rendered as follows: