Page Widget How to - Float Table Cells








Question

We would like to know how to float Table Cells.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
table {<!--from  w  w  w  . j a va2 s . com-->
  width: auto;
}

table td {
  background-color: lightgray;
  float: left;
  width: 150px;
  margin: 10px;
}
</style>
</head>
<body>
  <table>
    <tr>
      <td>First Row - Cell 1</td>
      <td>First Row - Cell 2</td>
    </tr>
    <tr>
      <td>Second Row - Cell 1</td>
      <td>Second Row - Cell 2</td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: