html - 是否可以剪辑表格列?

标签 html css

我想实现这样的目标。

table > tbody > tr > td:nth-child(2) {
  clip: rect(0px, 10px, 100px, 0px);
}

“隐藏”表格第三列的第一个 10px 是必要的。

起初尝试这不起作用,即使设置了 table-layout: fixed。有没有可能以某种方式解决这个问题?

我想尝试使用这种技术来实现具有“虚拟”水平滚动的固定列。

最佳答案

我的评论提示

  • 使用额外的容器并使用 negative 将其宽度几乎减小到零,但保持在流中。
  • 为您的 td 提供填充或宽度。

看来你只想显示 10px 宽度的一部分

从左边选择裁剪的方法

table > tbody > tr > td:nth-child(2) div {
  margin: 0 -999px 0 -10px;
  /* here -10px brings element in padding area of td and shows the first 10 px , to clip at 10px instead 0px do -20px idem for top margin */
  max-height: 100%;/* eventually & overflow:hidden ? */
  color:white
}
table > tbody > tr > td:nth-child(2) {
  padding-left: 10px;
  background: purple;
  overflow: hidden;
}
table > tbody > tr > td {
  background-color: orange;
}
/* example new clipping coordonates */
table + table > tbody > tr > td:nth-child(2) div {
  margin: -0.2em -999px 0 -3.75em;
}
<table>
  <tbody>
    <tr>
      <td>First Column</td>
      <td>
        <div>Second Column</div>
      </td>
      <td>Third Column</td>
    </tr>
  </tbody>
</table>
<table>
  <tbody>
    <tr>
      <td>First Column</td>
      <td>
        <div>Second Column</div>
      </td>
      <td>Third Column</td>
    </tr>
  </tbody>
</table>

从右边选择裁剪的方法

table > tbody > tr > td:nth-child(2) div {
  float: right;
  margin: 0 0 0 -9999px;
  color: white
}
table > tbody > tr > td:nth-child(2) {
  padding-left: 10px;
  background: purple;
  overflow: hidden;
}
table > tbody > tr > td {
  background-color: orange;
}
/* example new clipping coordonates */

table + table > tbody > tr > td:nth-child(2) div {
  margin: 0 -20px 0 -9999px;
}
<table>
  <tbody>
    <tr>
      <td>First Column</td>
      <td>
        <div>Second Column</div>
      </td>
      <td>Third Column</td>
    </tr>
  </tbody>
</table>
<table>
  <tbody>
    <tr>
      <td>First Column</td>
      <td>
        <div>Second Column</div>
      </td>
      <td>Third Column</td>
    </tr>
  </tbody>
</table>

关于html - 是否可以剪辑表格列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36089380/

相关文章:

html - 如何完全适合这个背景图片

html - xpath 在页面中查找包含 HTML 的链接

html - favicon 在 html5 样板中不起作用

html - 使用鼠标悬停定位工具提示

javascript - 要将图像附加到 html 按钮上的电子邮件,请单击

css - 根据子尺寸+边距展开父div

html - 将 XElement 转换为 HTML 字符串

css - 为什么我的部门在那里?

css - 删除链接事件状态的默认浏览器样式?

javascript - 带有透明圆圈的不透明半透明叠加层