左边一个跨度,右边一个跨度,其余的在下面

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

使用此 HTML

<th>
  <span class="left" > text to the left  </span>
  <span class="right"> text to the right </span>
  and then a lot of text below
</th>

CSS 会将第一个文本放在左侧,第二个文本放在右侧,以及这两个文本下面的所有其他内容,就像 HTML 一样

<th>
  <div>
    <span class="left">text to the left</span>
    <span class="right">text to the right</span>
  </div>
  and then a lot of text below
</th>

th     {overflow:auto}
.left  {float:left}
.right {float:right}

有弹性盒子吗?但下面的文本不在自己的 div 或 span 中。

css
1个回答
0
投票

它必须在

th
标签中吗?有
div
会更容易。

table {
  width: 100%;
}

th {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

th span {
  flex-basis: 50%;
}

.left {
  text-align: left;
}

.right {
  text-align: right;
}
<table>
  <tr>
    <th>
      <span class="left"> text to the left  </span>
      <span class="right"> text to the right </span> and then a lot of text below
    </th>
  </tr>
</table>

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