两个嵌套表中的顶部对齐问题

问题描述 投票:1回答:2

我有一个包含两个嵌套表的表,我正在努力让两者都正确对齐。每个表中的数据行可能不同。数据是动态的,我永远不会知道每个嵌套表1或2将有多少行。我需要确保标题始终排在最前面。

请参阅示例:https://jsfiddle.net/gbeford/arL48u0p/

<table style="display: table; border-color: grey; width: 100%">
<tr>
    <td style="padding:0; width:50%">
        <table style="display: table; border-color: grey; width: 100%">
            <thead>
                <tr style="background: gray;">
                    <th height="30" valign="bottom" data-key="payername1" data-sortable="" flex-size="default-100"><span>Payer
                            Name</span></th>
                    <th height="30" valign="bottom" data-key="payermethod1" data-sortable="" flex-size="default-100"><span
                            style="float:right;">Payment Method</span></th>
                </tr>
            </thead>
            <tbody>
                <tr style="background-color: #f5f5f5;">
                    <td>Test1</td>
                    <td class="col-ho-select-pymt">
                        <select name="pm1" id="pm1" style="width:85px; font-weight: normal;">
                            <option value="XXX">XXX</option>
                            <option value="YYY">YYY</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Test2</td>
                    <td class="col-ho-select-pymt">
                        <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                            <option value="XXX">XXX</option>
                            <option value="YYY">YYY</option>
                        </select>
                    </td>
                </tr>
                <tr style="background-color: #f5f5f5;">
                    <td>This is a long company name to test</td>
                    <td class="col-ho-select-pymt">
                        <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                            <option value="XXX">XXX</option>
                            <option value="YYY">YYY</option>
                    </td>
                </tr>
                <tr>
                    <td>Testing long name</td>
                    <td class="col-ho-select-pymt">
                        <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                            <option value="XXX">XXX</option>
                            <option value="YYY">YYY</option>
                    </td>
                </tr>
                <tr style="background-color: #f5f5f5;">
                    <td>Testing long name</td>
                    <td class="col-ho-select-pymt">
                        <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                            <option value="XXX">XXX</option>
                            <option value="YYY">YYY</option>
                    </td>
                </tr>
            </tbody>
        </table>
    </td>
    <td style="padding:0; width:50%">
        <table style="display: table; border-color: grey; width: 100%">
            <thead>
                <tr style="background: gray;">
                    <th height="30" valign="bottom" data-key="payername1" data-sortable=""><span>Payer Name</span></th>
                    <th height="30" valign="bottom" data-key="payermethod1" data-sortable=""><span style="float:right;">Payment
                            Method</span></th>
                </tr>
            </thead>
            <tbody>
                <tr style="background-color: #f5f5f5;">
                    <td>Test1</td>
                    <td style="float:right;">
                        <select name="pm1" id="pm1" style="width:85px; font-weight: normal;">
                            <option value="XXX">XXX</option>
                            <option value="YYY">YYY</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Test12</td>
                    <td style="float:right;">
                        <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                            <option value="XXX">XXX</option>
                            <option value="YYY">YYY</option>
                        </select>
                    </td>
                </tr>
                <tr style="background-color: #f5f5f5;">
                    <td>This is a long company name to test</td>
                    <td style="float:right;">
                        <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                            <option value="XXX">XXX</option>
                            <option value="YYY">YYY</option>
                        </select>
                    </td>
                </tr>
            </tbody>
        </table>
    </td>
</tr>

html css html-table
2个回答
0
投票

你可以在你的顶级vertical-align: top上使用<tr>获得你想要的结果。试试下面的代码:

<table style="display: table; border-color: grey; width: 100%">
  <tr style="vertical-align: top;">
    <td style="padding:0; width:50%">
      <table style="display: table; border-color: grey; width: 100%">
        <thead>
          <tr style="background: gray;">
            <th height="30" valign="bottom" data-key="payername1" data-sortable="" flex-size="default-100"><span>Payer
                                Name</span></th>
            <th height="30" valign="bottom" data-key="payermethod1" data-sortable="" flex-size="default-100"><span style="float:right;">Payment Method</span></th>
          </tr>
        </thead>
        <tbody>
          <tr style="background-color: #f5f5f5;">
            <td>Test1</td>
            <td class="col-ho-select-pymt">
              <select name="pm1" id="pm1" style="width:85px; font-weight: normal;">
                <option value="XXX">XXX</option>
                <option value="YYY">YYY</option>
              </select>
            </td>
          </tr>
          <tr>
            <td>Test2</td>
            <td class="col-ho-select-pymt">
              <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                <option value="XXX">XXX</option>
                <option value="YYY">YYY</option>
              </select>
            </td>
          </tr>
          <tr style="background-color: #f5f5f5;">
            <td>This is a long company name to test</td>
            <td class="col-ho-select-pymt">
              <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                <option value="XXX">XXX</option>
                <option value="YYY">YYY</option>
            </td>
          </tr>
          <tr>
            <td>Testing long name</td>
            <td class="col-ho-select-pymt">
              <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                <option value="XXX">XXX</option>
                <option value="YYY">YYY</option>
            </td>
          </tr>
          <tr style="background-color: #f5f5f5;">
            <td>Testing long name</td>
            <td class="col-ho-select-pymt">
              <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                <option value="XXX">XXX</option>
                <option value="YYY">YYY</option>
            </td>
          </tr>
        </tbody>
      </table>
    </td>
    <td style="padding:0; width:50%">
      <table style="display: table; border-color: grey; width: 100%">
        <thead>
          <tr style="background: gray;">
            <th height="30" valign="bottom" data-key="payername1" data-sortable=""><span>Payer Name</span></th>
            <th height="30" valign="bottom" data-key="payermethod1" data-sortable=""><span style="float:right;">Payment
                                Method</span></th>
          </tr>
        </thead>
        <tbody>
          <tr style="background-color: #f5f5f5;">
            <td>Test1</td>
            <td style="float:right;">
              <select name="pm1" id="pm1" style="width:85px; font-weight: normal;">
                <option value="XXX">XXX</option>
                <option value="YYY">YYY</option>
              </select>
            </td>
          </tr>
          <tr>
            <td>Test12</td>
            <td style="float:right;">
              <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                <option value="XXX">XXX</option>
                <option value="YYY">YYY</option>
              </select>
            </td>
          </tr>
          <tr style="background-color: #f5f5f5;">
            <td>This is a long company name to test</td>
            <td style="float:right;">
              <select name="pm3" id="pm3" style="width:85px; font-weight: normal;">
                <option value="XXX">XXX</option>
                <option value="YYY">YYY</option>
              </select>
            </td>
          </tr>
        </tbody>
      </table>
    </td>
  </tr>
</table>

0
投票

我找到了问题的答案。所以不要用这个老学校的css :)

答案vertical-align:top;

© www.soinside.com 2019 - 2024. All rights reserved.