Column Resizing

Changes column width.

Customer orders
Order Customer Status Total
#1042A. WhitfieldShipped£64.00
#1041R. OkaforProcessing£128.50
#1040M. IqbalShipped£22.00
#1039S. NovakRefunded£40.00

html

<div class="crsz" style="--accent:#241430;">
  <div class="crsz__scroll">
    <table class="crsz__table">
      <caption>Customer orders</caption>
      <thead><tr>
        <th scope="col">Order</th>
        <th scope="col" class="crsz__customer" style="width:140px;">Customer<span class="crsz__resizer" aria-hidden="true"></span></th>
        <th scope="col">Status</th>
        <th scope="col">Total</th>
      </tr></thead>
      <tbody>
        <tr><td>#1042</td><td class="crsz__cell" style="width:140px;">A. Whitfield</td><td>Shipped</td><td>£64.00</td></tr>
        <tr><td>#1041</td><td class="crsz__cell" style="width:140px;">R. Okafor</td><td>Processing</td><td>£128.50</td></tr>
        <tr><td>#1040</td><td class="crsz__cell" style="width:140px;">M. Iqbal</td><td>Shipped</td><td>£22.00</td></tr>
        <tr><td>#1039</td><td class="crsz__cell" style="width:140px;">S. Novak</td><td>Refunded</td><td>£40.00</td></tr>
      </tbody>
    </table>
  </div>
</div>
<style>
.crsz { font: 14px system-ui, sans-serif; color: #241430; background: #FAF7F2; max-width: 480px; border: 1px solid #24143020; border-radius: 10px; overflow: hidden; }
.crsz__scroll { overflow-x: auto; }
.crsz__table { border-collapse: collapse; width: 100%; table-layout: fixed; }
.crsz__table caption { text-align: left; font-weight: 600; padding: 10px 14px; }
.crsz__table th, .crsz__table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid #24143020; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crsz__table th { background: var(--accent); color: #FAF7F2; }
.crsz__customer { position: relative; }
.crsz__resizer { position: absolute; top: 0; right: 0; bottom: 0; width: 8px; cursor: col-resize; }
.crsz__resizer:hover, .crsz__resizer:focus-visible { background: #FAF7F250; }
.crsz__guide { position: absolute; top: 0; bottom: -400px; left: 100px; border-left: 1px dashed #24143080; pointer-events: none; }
</style>

tailwind

<div class="max-w-[480px] rounded-[10px] border border-[#24143020] font-sans text-sm text-[#241430] bg-[#FAF7F2] overflow-hidden" style="--accent:#241430;">
  <div class="overflow-x-auto">
    <table class="border-collapse w-full table-fixed">
      <caption class="text-left font-semibold px-3.5 py-2.5">Customer orders</caption>
      <thead><tr class="text-[#FAF7F2]" style="background:#241430">
        <th scope="col" class="p-3.5 text-left whitespace-nowrap">Order</th>
        <th scope="col" class="relative p-3.5 text-left whitespace-nowrap overflow-hidden text-ellipsis" style="width:140px">Customer<span aria-hidden="true" class="absolute top-0 right-0 bottom-0 w-2 cursor-col-resize hover:bg-white/30"></span></th>
        <th scope="col" class="p-3.5 text-left whitespace-nowrap">Status</th>
        <th scope="col" class="p-3.5 text-left whitespace-nowrap">Total</th>
      </tr></thead>
      <tbody>
        <tr><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">#1042</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap overflow-hidden text-ellipsis" style="width:140px">A. Whitfield</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">Shipped</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">£64.00</td></tr>
        <tr><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">#1041</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap overflow-hidden text-ellipsis" style="width:140px">R. Okafor</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">Processing</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">£128.50</td></tr>
        <tr><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">#1040</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap overflow-hidden text-ellipsis" style="width:140px">M. Iqbal</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">Shipped</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">£22.00</td></tr>
        <tr><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">#1039</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap overflow-hidden text-ellipsis" style="width:140px">S. Novak</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">Refunded</td><td class="p-3.5 border-b border-[#24143020] whitespace-nowrap">£40.00</td></tr>
      </tbody>
    </table>
  </div>
</div>

react

function ColumnResizing({
  caption = "Customer orders",
  accent = "#241430",
  columnWidth = 140,
  resizerVisible = true,
  minWidthGuide = false,
}) {
  const rows = [
    ["#1042", "A. Whitfield", "Shipped", "£64.00"],
    ["#1041", "R. Okafor", "Processing", "£128.50"],
    ["#1040", "M. Iqbal", "Shipped", "£22.00"],
    ["#1039", "S. Novak", "Refunded", "£40.00"],
  ];
  const cell = { padding: "10px 14px", borderBottom: "1px solid #24143020", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" };
  return (
    <div style={{ maxWidth: 480, borderRadius: 10, border: "1px solid #24143020", overflow: "hidden", font: "14px system-ui, sans-serif", color: "#241430", background: "#FAF7F2" }}>
      <div style={{ overflowX: "auto" }}>
        <table style={{ borderCollapse: "collapse", width: "100%", tableLayout: "fixed" }}>
          <caption style={{ textAlign: "left", fontWeight: 600, padding: "10px 14px" }}>{caption}</caption>
          <thead>
            <tr style={{ background: accent, color: "#FAF7F2" }}>
              <th scope="col" style={cell}>Order</th>
              <th scope="col" style={{ ...cell, width: columnWidth, position: "relative" }}>
                Customer
                {resizerVisible && <span aria-hidden="true" style={{ position: "absolute", top: 0, right: 0, bottom: 0, width: 8, cursor: "col-resize" }} />}
                {minWidthGuide && <span aria-hidden="true" style={{ position: "absolute", top: 0, bottom: -400, left: 100, borderLeft: "1px dashed #24143080", pointerEvents: "none" }} />}
              </th>
              <th scope="col" style={cell}>Status</th>
              <th scope="col" style={cell}>Total</th>
            </tr>
          </thead>
          <tbody>
            {rows.map((row) => (
              <tr key={row[0]}>
                <td style={cell}>{row[0]}</td>
                <td style={{ ...cell, width: columnWidth }}>{row[1]}</td>
                <td style={cell}>{row[2]}</td>
                <td style={cell}>{row[3]}</td>
              </tr>
            ))}
          </tbody>
        </table>
      </div>
    </div>
  );
}