Skip to content
TheChatArchiveThe Chat Archive
Qwenqwen3-30b-a3b· Alibaba (Qwen)Hugging Face LMArena Human Preference 140K

Thank you. How about freezing the first two columns?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Amazon Novaamazon.nova-pro-v1:0’s answer.
  1. User

    Thank you. How about freezing the first two columns?

  2. Qwen Assistant

    To freeze the first two columns of a table while scrolling vertically, you need to use position: sticky on both the first and second columns in both the header (<th>) and the body (<td>).

    However, due to how position: sticky works, simply applying it to both columns without proper positioning will cause them to overlap. To avoid this, you need to explicitly define the left position of each column based on the width of the previous column.


    ✅ Solution: Freeze First Two Columns

    Here's a complete HTML file that demonstrates how to freeze the first two columns of a table:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Freeze First Two Columns</title>
      <style>
        body {
          padding: 20px;
        }
    
        table {
          border-collapse: collapse;
          width: 100%;
          table-layout: fixed;
          max-height: 400px;
          overflow: auto;
        }
    
        th, td {
          border: 1px solid #ccc;
          padding: 10px;
          text-align: left;
        }
    
        th {
          background-color: #f2f2f2;
        }
    
        /* Freeze the first two columns */
        th:nth-child(1), td:nth-child(1) {
          width: 120px; /* Set fixed width for the first column */
          position: sticky;
          left: 0;
          z-index: 2;
        }
    
        th:nth-child(2), td:nth-child(2) {
          width: 150px; /* Set fixed width for the second column */
          position: sticky;
          left: 120px; /* Match the width of the first column */
          z-index: 1;
        }
    
        /* Ensure header row is also sticky */
        th:nth-child(1), th:nth-child(2) {
          position: sticky;
          top: 0;
          z-index: 3;
        }
      </style>
    </head>
    <body>
    
      <table>
        <thead>
          <tr>
            <th>Header 1</th>
            <th>Header 2</th>
            <th>Header 3</th>
            <th>Header 4</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Row 1 Col 1</td>
            <td>Row 1 Col 2</td>
            <td>Row 1 Col 3</td>
            <td>Row 1 Col 4</td>
          </tr>
          <tr>
            <td>Row 2 Col 1</td>
            <td>Row 2 Col 2</td>
            <td>Row 2 Col 3</td>
            <td>Row 2 Col 4</td>
          </tr>
          <tr>
            <td>Row 3 Col 1</td>
            <td>Row 3 Col 2</td>
            <td>Row 3 Col 3</td>
            <td>Row 3 Col 4</td>
          </tr>
          <tr>
            <td>Row 4 Col 1</td>
            <td>Row 4 Col 2</td>
            <td>Row 4 Col 3</td>
            <td>Row 4 Col 4</td>
          </tr>
          <tr>
            <td>Row 5 Col 1</td>
            <td>Row 5 Col 2</td>
            <td>Row 5 Col 3</td>
            <td>Row 5 Col 4</td>
          </tr>
          <!-- Add more rows for scrolling -->
          <tr>
            <td>Row 6 Col 1</td>
            <td>Row 6 Col 2</td>
            <td>Row 6 Col 3</td>
            <td>Row 6 Col 4</td>
          </tr>
          <tr>
            <td>Row 7 Col 1</td>
            <td>Row 7 Col 2</td>
            <td>Row 7 Col 3</td>
            <td>Row 7 Col 4</td>
          </tr>
          <tr>
            <td>Row 8 Col 1</td>
            <td>Row 8 Col 2</td>
            <td>Row 8 Col 3</td>
            <td>Row 8 Col 4</td>
          </tr>
          <tr>
            <td>Row 9 Col 1</td>
            <td>Row 9 Col 2</td>
            <td>Row 9 Col 3</td>
            <td>Row 9 Col 4</td>
          </tr>
          <tr>
            <td>Row 10 Col 1</td>
            <td>Row 10 Col 2</td>
            <td>Row 10 Col 3</td>
            <td>Row 10 Col 4</td>
          </tr>
        </tbody>
      </table>
    
    </body>
    </html>
    

    🔍 Key Points

    • Fixed Column Widths: We define width for the first two columns using th:nth-child(1) and th:nth-child(2) to ensure position: sticky works correctly.
    • Sticky Positioning:
      • The first column is position: sticky with left: 0.
      • The second column is position: sticky with left: 120px (equal to the first column's width).
    • Z-Index: Ensures that the first column stays above the second, and the header row is above both.

    ⚠️ Limitations

    • This approach requires fixed column widths to work correctly.
    • If you're using table-layout: auto, this method may not work reliably across all browsers.

    ✅ Result

    When you scroll vertically, the first two columns will remain fixed in place, just like the original header row. This makes it easier to track data in large tables.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.