在 td 元素中将按钮右对齐

Rol*_*and 5 html css html-table css-float

我有一个<td>包含内容和按钮的元素。内容的宽度width应该是除按钮宽度之外的所有内容,按钮的宽度将被固定。该按钮应与内容的右侧对齐。我怎样才能实现这一点,以下不起作用:

<table border="1px">
  <tr>
    <td>
      <div>
        <div style="width: auto; overflow: auto;">
          <span>
            <form>
            <textarea></textarea>
            </form>
          </span>
        </div>
        <div style="float: right; width: 32px;">
          <button type="button" class="btn btn-primary">
            Click
          </button>
        </div>
      </div>
    </td>
    <td>Another cell</td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

Him*_*sal 5

使用 style="float: right;"

<table border="1px">
  <tr>
    <td>
      <div style="display:inline-block">
        <div style="display: inherit;width: calc(100% - 32px);overflow: auto;">
          <span>
            <form>
            <textarea></textarea>
            </form>
          </span>
        </div>
        <div style="float: right; width: 32px;">
          <button type="button" class="btn btn-primary" title="Select Financial Instrument" style="width:100%; word-wrap: break-word;">
            Click
          </button>
        </div>
      </div>
    </td>
    <td>Another cell</td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)


Rol*_*and 3

根据杰拉德的回答,以下内容最适合我:

<table border="1px">
  <tr>
    <td>
      <div style="display: inline-flex; align-items: center; width: 100%;">
        <div>
          <span>
            <form>
            <textarea></textarea>
            </form>
          </span>
        </div>
        <div style="padding: 5px;">
          <button type="button">
            Click
          </button>
        </div>
      </div>
    </td>
    <td>Another cell</td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)