【问题标题】:Removing the space between cells of a grid [duplicate]删除网格单元格之间的空间[重复]
【发布时间】:2016-10-31 18:44:12
【问题描述】:

我想删除单元格之间的空格,使网格看起来有点像方格纸。现在单元格之间有一个小空间,我想删除它。

这是我现在拥有的:

function generateGrid(rows, cols) {
  var grid = "<table>";
  for (row = 1; row <= rows; row++) {
    grid += "<tr>";
    for (col = 1; col <= cols; col++) {
      grid += "<td></td>";
    }
    grid += "</tr>";
  }
  return grid;
}

$("#tableContainer").append(generateGrid(5, 5));

$("td").click(function() {
  var index = $("td").index(this);
  var row = Math.floor((index) / 5) + 1;
  var col = (index % 5) + 1;
  $("span").text("That was row " + row + " and col " + col);
  $(this).css('background-color', 'red');
});
td {
  border: 1px solid;
  width: 50px;
  height: 50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<span>Select a cell!</span>
<div id="tableContainer"></div>

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:

    在您的 CSS 中:

    table {
        border-collapse: collapse;
    }
    

    【讨论】:

      【解决方案2】:
      table {
          border-collapse: collapse;
      }
      th, td {
          padding: 0;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-03
        • 2015-05-01
        • 2012-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多