HTML Element Style How to - Add border to table cell when focused








Question

We would like to know how to add border to table cell when focused.

Answer


<!-- ww  w .j  a  v a 2s . c o m-->
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
td {
  width: 200px;
}

td:focus {
  border: 2px inset white;
  border-width: 2px;
  content: '';
  position: absolute;
  background: white;
}
</style>
</head>
<body>
  <table>
    <tbody>
      <tr>
        <td contenteditable> Click me</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

The code above is rendered as follows: