HTML Element Style How to - Set div width in TD in table cell








Question

We would like to know how to set div width in TD in table cell.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {<!--from  w  ww.j a  v  a  2  s  .c  o  m-->
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100px;
}

td {
  white-space: nowrap;
}
</style>
</head>
<body>
  <table>
    <tr>
      <td>
        <div>Here is plenty of text to cut</div>
      </td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: