Combining a table and hierarchical list in HTML

前端 未结 7 1289
无人共我
无人共我 2021-02-05 05:45

I\'m working to redesign a legacy toolset and I\'m looking at how to better display some information both presentationally and semantically.

The data hierarchically in n

相关标签:
7条回答
  • 2021-02-05 06:22

    UPDATE: I've added the use of IDs and "headers" attribute to, somehow, semantically mark up the hierarchy.

    That's definitively tabular data (you should really push the definition of "list" to justify using an UL or DL here!).

    I think a good approach would be using different tbodys to group those related rows together (something like this it used here http://www.w3.org/TR/2012/WD-html5-20120329/the-table-element.html#the-table-element see "table being used to mark up a Sudoku puzzle")

    <table>
      <thead>
        <tr>
          <th id="seq">Seq</th>
          <th>Item Name</th>
          <th>Min</th>
          <th>Max</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th id="s1" headers="seq">1</th>
          <td>Identifier</td>
          <td>1</td>
          <td>1</td>
        </tr>
      </tbody>
      <tbody>
        <tr>
          <th id="s2" headers="seq">2</th>
          <td>Name</td>
          <td>1</td>
          <td>1</td>
        </tr>
        <tr class="sub">
          <th id="s2_1" headers="seq s2">2.1</th>
          <td>First Name</td>
          <td>1</td>
          <td>1</td>
        </tr>
        <tr class="sub">
          <th id="s2_2" headers="seq s2">2.2</th>
          <td>Middle Name</td>
          <td>-</td>
          <td>-</td>
        </tr>
        <tr class="sub">
          <th id="s2_3" headers="seq s2">2.3</th>
          <td>Last Name</td>
          <td>1</td>
          <td>1</td>
        </tr>
        <tr class="sub sub">
          <th id="s2_3_1" headers="seq s2 s2_3">2.3.1</th>
          <td>Last Name</td>
          <td>1</td>
          <td>1</td>
        </tr>
        <tr class="sub sub">
          <th id="s2_3_2" headers="seq s2 s2_3">2.3.2</th>
          <td>Last Name</td>
          <td>1</td>
          <td>1</td>
        </tr>
      </tbody>
      <tbody>
        <tr>
          <th id="s3" headers="seq">3</th>
          <td>Age</td>
          <td>-</td>
          <td>1</td>
        </tr>
      </tbody>
    </table>
    

    Then you could use something like this:

    table { border-collapse: collapse; }
    tbody { border-bottom:1px solid #000; }
    tbody .sub td { padding-left: 10px; }
    

    If fact, I think you can only use tbody to group rows together and leave single rows alone

    <tr>
      <td>1</td>
      <td>Identifier</td>
      <td>1</td>
      <td>1</td>
    </tr>
    <tbody>
      <tr>
        <td>2</td>
        <td>Name</td>
        <td>1</td>
        <td>1</td>
      </tr>
      <tr class="sub">
        <td>2.1</td>
        <td>First Name</td>
        <td>1</td>
        <td>1</td>
      </tr>
      ...
    </tbody>
    <tr>
      <td>3</td>
      <td>Age</td>
      <td>-</td>
      <td>1</td>
    </tr>
    
    0 讨论(0)
提交回复
热议问题