Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can enable dragging to resize columns in an HTML table by adding the following style code to the table:

table {
  table-layout: fixed;
  width: 100%;
}

th {
  position: relative;
  cursor: col-resize;
}

th::after {
  content: "";
  position: absolute;
  top: 0;
  right: -5px;
  bottom: 0;
  width: 10px;
  background-color: #e5e5e5;
}

This style code sets the table layout to fixed and makes it 100% width. It also sets the cursor of the table header cells to col-resize so that the user can click and drag to resize the columns.

In addition, it adds a pseudo-element (::after) to the table headers to create a draggable area to resize the columns. The right position is set to -5px so that the draggable area doesn't overlap with the table border. The background color is set to make it visually distinct.

Note that this method only works on desktop devices and may not be suitable for smaller screens or touch devices.