【问题标题】:CSS Make user text selection vertically in tableCSS在表格中垂直选择用户文本
【发布时间】:2021-09-04 14:55:07
【问题描述】:

我想创建一个表,但我希望用户能够先选择列,然后选择第二列,依此类推(而不是先选择行的方式)。

First Second
This is the first message This is the second message
This is the first message in the second row This is the second message in the second row

(只有斜体的东西应该由用户一次选择,其他的也一样)

因此,当我选择“第一个”并以“这是第二行中的第一条消息”结束选择时,它应该只选择“这是第一条消息 em>”而不是“Second”和“This is the second message”。


我尝试过user-select: none;,但这仅在我只希望用户能够选择一列时才有效。

【问题讨论】:

  • 为什么用户选择一列中的所有内容?
  • @NathanielFlick 用户应该这样做,并且选择是基于行的。我希望这样,因为我希望用户能够复制 collums 并将其直接粘贴,就好像行之间的行不存在一样。
  • 您是否考虑过使用 Datatables JS 为您的表格添加更多高级功能? datatables.net
  • @Nathaniel Flick 不,因为我不需要所有这些功能。
  • 你不必使用所有的功能,但我敢打赌它有你需要的东西

标签: html css highlight textselection


【解决方案1】:

您可以通过嵌套表格来实现:

table{
  text-align:left;
}
<table>
  <tr>
    <td>
      <table>
        <tr>
          <th>First</th>
        </tr>
        <tr>
          <td>This is the first message</td>
        </tr>
        <tr>
          <td>This is the first message in the second row</td>
        </tr>
      </table>
    </td>

    <td>
      <table>
        <tr>
          <th>Second</th>
        </tr>
        <tr>
          <td>This is the second message</td>
        </tr>
        <tr>
          <td>This is the second message in the second row</td>
        </tr>
      </table>
    </td>
  </tr>
</table>

【讨论】:

  • 是的(谢谢),但不幸的是,这并不像一张桌子那样工作。 (而且我需要相邻的单元格具有相同高度的这种行为)。
  • @QuickWrite 您所说的“这与表格的工作方式不同”是什么意思?
  • 当我创建一个&lt;td&gt; 元素并将内容插入该元素时,它会计算高度。这个高度被转移到&lt;tr&gt;-tag 中的所有其他元素。但不幸的是,这不在这里,好像我做This is the first &lt;br&gt; message td 与This is the second message 内容的td 的高度不同(很抱歉我的问题不清楚)
猜你喜欢
  • 1970-01-01
  • 2016-02-11
  • 2013-12-28
  • 2019-08-01
  • 2014-10-22
  • 1970-01-01
  • 1970-01-01
  • 2021-11-08
  • 2011-07-23
相关资源
最近更新 更多