html - 如何隐藏表格边缘的行和列?

标签 html css

例如,我有一张 82x82 的 table 。但我只想显示表格的中央 80x80 部分。隐藏的表格单元格仍然会有一些数据,我只是不想显示它们。我的想法是将表格放入一个 div 中,以隐藏表格中不必要的部分。像这样:

#workspace {
  position: absolute;
  width: 800px;
  height: 800px;
  top: 50%;
  left: 50%;
  margin-left: -400px;
  margin-top: -400px;
  overflow: hidden;
}

table {
  position: absolute;
  margin-left: -10px;
  margin-top: -10px;
  width: 820px;
  height: 820px;
}
<div id="workspace">
  <table>

  </table>
</div>

但是当我在 Mozilla 中打开控制台时,我看到了一部分隐藏的单元格(见表底部): enter image description here

所以我的问题是如何解决这个问题?或者建议我使用其他方法来隐藏表格中不需要的部分?

附言表格单元格是用 javascript 创建的

最佳答案

使用 nth-child() 选择器获取和隐藏边缘的表格元素。

 tr:first-child,
 tr:last-child,
 td:first-child,
 td:last-child {
   display: none
 }

关于html - 如何隐藏表格边缘的行和列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53846681/

相关文章:

html - 列表中元素之间的垂直间距

html - @supports 规则如何支持此语句中的动画名称?

javascript - 在输入字段中仅粘贴数字

html - 将表格右对齐时的 Div 高度问题

php - 无法显示/计算一组文本字段的总值 - angular js html php

javascript - 鼠标松开事件不会时常发生

javascript - 根据参数通过 Javascript 替换表体

html - 试图在类别下的页面上显示标题

css - 在相对定位的父 div 下面对绝对定位的子 div 的 z-indexing 问题

css - <h1> 只允许 12px margin-bottom,然后让我的页面向左浮动