gpt4 book ai didi

html - 改变 td 的宽度

转载 作者:行者123 更新时间:2023-11-28 00:38:38 25 4
gpt4 key购买 nike

我构建了一个带有可滚动表体的表。现在我在调整表格数据单元格的宽度时遇到了一些困难。更改 td 的宽度值对大小没有影响。请看下面的代码。

此代码段包含 HTML 和 CSS:

#d2 {
border: solid black;
width: 20%;
height: 28%;
display: inline-block;
overflow-x: auto;
}

#d1 {
border: solid black;
display: inline-block;
width: 8%;
height: 28%;
}

tr {
width: 100vw;
}

td {
border: solid black;
width: 100px;
/* changing the value of the width here have no effect*/
height: 7vh;
}

#tro1,
#tro2,
#tro3 {
display: block;
border: solid black;
height: 7.4vh;
width: 7vw;
}
<div id='d1'>
<table>
<tr id='tro1'>
<th> Centro</th>
</tr>
<tr id='tro2'>
<th>Date</th>
</tr>
<tr id='tro3'>
<th>Date</th>
</tr>
</table>


</div>

<div id='d2'>
<table>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
<td>Mexico</td>
<td>Mexico</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
<td>Mexico</td>
<td>Mexico</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
<td>Mexico</td>
<td>Mexico</td>
</tr>
</table>
</div>

最佳答案

如果你只想改变 td 的宽度,那么你也可以使用 CSS 的 min-width 属性。

HTML 和 CSS:

#d2 {
border: solid black;
width: 20%;
height: 28%;
display: inline-block;
overflow-x: auto;
}

#d1 {
border: solid black;
display: inline-block;
width: 8%;
height: 28%;
}

tr {
width: 100vw;
}

td {
border: solid black;
width: 100px;
/* changing the value of the width here have no effect*/
height: 7vh;
min-width: 200px;
/* changing the value of the width will work with min width bro*/
}

#tro1,
#tro2,
#tro3 {
display: block;
border: solid black;
height: 7.4vh;
width: 7vw;
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="td.css">
<title>Document</title>
</head>

<body>
<div id='d1'>
<table>
<tr id='tro1'>
<th> Centro</th>
</tr>
<tr id='tro2'>
<th>Date</th>
</tr>
<tr id='tro3'>
<th>Date</th>
</tr>
</table>


</div>

<div id='d2'>
<table>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
<td>Mexico</td>
<td>Mexico</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
<td>Mexico</td>
<td>Mexico</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
<td>Mexico</td>
<td>Mexico</td>
</tr>
</table>
</div>
</body>

</html>

jsfiddle 输出: https://jsfiddle.net/defenderkhan/54ufsy1m/2/

您也可以使用 Bootstrap 4 classes 轻松完成它.

关于html - 改变 td 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54871640/

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