gpt4 book ai didi

html - CSS 和表格边框问题

转载 作者:太空宇宙 更新时间:2023-11-04 16:03:04 26 4
gpt4 key购买 nike

我正在尝试制作一个具有 10x10 瓷砖的蓝色背景的网格。所有的方 block 都需要是正方形的,并且需要用蓝色填充,并用一条黑色的小线分隔每个方 block 。当我在 CSS 中格式化表格时,它的边缘太宽,这是一个小问题,但相当恼人。我看不出问题是什么,其他人可以吗?

var boatStatusClient = "";
var x_client = 0;
var y_client = 0;
var battlefield_client = "";

var source_client;
var boatGrid = {
placeBoat_client: function() {
source_client = event.target || event.srcElement;
source_client = source_client.id
source_client.id = document.getElementById(source_client.id);
document.getElementById(source_client).style.backgroundColor = "orange";

},
}

for (y_client = 1; y_client < 11; y_client++) {
battlefield_client += "<tr>";
for (x_client = 1; x_client < 11; x_client++) {
battlefield_client += "<td onclick = '' class = 'tile' style='border: 3px solid black;' id=" + "cell_client_" + x_client + "_" + y_client + ">&nbsp</td>";
}
battlefield_client += "</tr>";
}

$(document).ready(function() {
$("#tableGrid_client").html(battlefield_client); //loads table

for (y_client = 1; y_client < 11; y_client++) {
for (x_client = 1; x_client < 11; x_client++) {
boatStatusClient = document.getElementById('cell_client_' + x_client + "_" + y_client);
boatStatusClient.addEventListener("click", function() {
boatGrid.placeBoat_client()
});
}
}
});
table {
border-collapse: collapse;
border: none;
}
.tile {
background-color: #34B0D9;
cursor: pointer;
}
.tile:hover {
background-color: #6fcdec;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="hideGames">
<table style="position:absolute; top: 20px; left: 20px; border:6px solid #ff5050; width: 500px; height: 500px;" id="tableGrid_client"></table>

最佳答案

你只需要添加 table-layout:fixed到你的

fixed

Table and column widths are set by the widths of table and col elements or by the width of the first row of cells. Cells in subsequent rows do not affect column widths.

Under the "fixed" layout method, the entire table can be rendered once the first table row has been downloaded and analyzed. This can speed up rendering time over the "automatic" layout method, but subsequent cell content may not fit in the column widths provided. Any cell that has content that overflows uses the overflow property to determine whether to clip the overflow content.

注意:避免内联样式。

    var boatStatusClient = "";
var x_client = 0;
var y_client = 0;
var battlefield_client = "";

for (y_client = 1; y_client < 11; y_client++) {
battlefield_client += "<tr>";
for (x_client = 1; x_client < 11; x_client++) {
battlefield_client += "<td onclick = '' class = 'tile' style='border: 3px solid black;' id=" + "cell_client_" + x_client + "_" + y_client + ">&nbsp</td>";
}
battlefield_client += "</tr>";
}
$(document).ready(function() {
$("#tableGrid_client").html(battlefield_client); //loads table

for (y_client = 1; y_client < 11; y_client++) {
for (x_client = 1; x_client < 11; x_client++) {
boatStatusClient = document.getElementById('cell_client_' + x_client + "_" + y_client);
boatStatusClient.addEventListener("click", function() {
boatGrid.placeBoat_client()
});
}
}
});
body {
font-size: 118%;
font-family: calibri light;
background-color: #E8E8E8
}
table {
border-collapse: collapse;
border: none;
table-layout: fixed;
position: absolute;
top: 20px;
left: 20px;
border: 6px solid #ff5050;
width: 500px;
height: 500px;
}
.tile {
background-color: #34B0D9;
cursor: pointer;
}
.tile:hover {
background-color: #6fcdec;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<body>
<!--START OF GAMES PART-->
<div class="hideGames">
<table style="" id="tableGrid_client"></table>
</div>
<!--END OF GAMES PART -->

关于html - CSS 和表格边框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40433390/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com