首页 > 解决方案 > 如何将有序列表项表与数字对齐?

问题描述

我有一个使用下面的代码包含 1 行和 2 列的表的有序列表。

我试图让表格段落的第一行与类似于普通列表项的数字对齐。由于某种原因,它没有对齐,并且数字显示在底部。

我该如何 1. 将表格行段落与第一项类似的数字对齐 2. 将“56 引文”段落与表格中的另一个 td 对齐。

谢谢!

<ol>
  <li>
    <p>This is what a normal item</p>
    <p>looks</p>
    <p>like</p>
  </li>
  <li>
    <table>
      <tr>
        <td>
          <p>This is what a table item</p>
          <p>looks</p>
          <p>like</p>
        </td>
        <td>
          <p>56 Citations</p>
        </td>
      </tr>
      </table>
  </li>
</ol>

Firefox 中 html 的渲染

标签: htmlcsshtml-tablehtml-lists

解决方案


vertical-align: baselinetd元素中使用,如下所示:

td {
  vertical-align: baseline;
}
<ol>
  <li>
    <p>This is what a normal item</p>
    <p>looks</p>
    <p>like</p>
  </li>
  <li>
    <table>
      <tr>
        <td>
          <p>This is what a table item</p>
          <p>looks</p>
          <p>like</p>
        </td>
        <td>
          <p>56 Citations</p>
        </td>
      </tr>
    </table>
  </li>
</ol>


推荐阅读