Page Widget How to - Truncate table cell with really long string








Question

We would like to know how to truncate table cell with really long string.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
table {<!--  w  ww. ja va2  s  . c  o m-->
  width: 100%;
  border: 1px solid #ccc;
}

td {
  padding: 14px;
  line-height: 1.5;
  border: 1px solid #ccc;
}

.outer {
  position: relative;
  height: 22px;
}

.inner {
  position: absolute;
  overflow: hidden;
  width: 100%;
  white-space: nowrap;
  margin: auto;
  top: 0;
  bottom: 0;
}
</style>
</head>
<body>
  <table>
    <tr>
      <td>
        <div class="outer">
          <div class="inner">this_is_a_really_long_string_of_text</div>
        </div>
      </td>
      <td>222222222</td>
    </tr>
  </table>
</body>
</html>

The code above is rendered as follows: