html - 我希望所有表格行的高度相同,并且列可以滚动(如果需要)
问题描述
我编写了一个代码,应该使所有行的高度相同,如果列中的信息多于适合的信息,则应该出现一个滚动条。目前,虽然有些行变得更大,但没有出现滚动条。
var table = '<table>';
for (let i = 0; i < 6; i++) {
var item = jsonData\[i\];
table += '<tr>';
table += '<td align="left" class="align-middle" height="65px">'
+item.firstName+'</td>';
table += '<td class="align-middle" height="65px" overflow-y="auto">'
+item.agegroup+'</td>';
table += '<td class="align-middle" height="65px" overflow-y="auto">'
+item.subject+'</td>';
table += '<td class="align-middle" height="65px" overflow-y="auto">'
+item.location+'</td>';
table += '</tr>';
}
table += '</table>';
document.getElementById("fulltable").innerHTML = table;
解决方案
You can add a div inside <td>
and add height and overflow: auto; on that div
table{
table-layout: fixed;
width: 100%;
}
table tr td .scroll{
height:65px;
overflow:auto;
}
<table>
<tr>
<td align="left" class="align-middle"><div class="scroll">Lorem Ipsum</div></td>
<td class="align-middle"><div class="scroll">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</div></td>
<td class="align-middle"><div class="scroll">Lorem Ipsum</div></td>
<td class="align-middle"><div class="scroll">Lorem Ipsum</div></td>
</tr>
<tr>
<td align="left" class="align-middle"><div class="scroll">Lorem Ipsum</div></td>
<td class="align-middle"><div class="scroll">Industry Lorem Ipsum has been the industry's standard dummy text ever since the 1500 Lorem Ipsum is simply dummy text of the printing and typesetting</div></td>
<td class="align-middle"><div class="scroll">Lorem Ipsum</div></td>
<td class="align-middle"><div class="scroll">Lorem Ipsum</div></td>
</tr>
</table>
推荐阅读
- git - 如何在子模块树中添加自定义文件夹
- linux - 在 Bash 中用字符串替换命令
- json - JMeter 中的 POST 给出“无法识别的令牌 'json'”
- python - 如何在 Selenium 中从主页移动到下一页以提取帖子的完整信息
- javascript - 如何在 JavaScript 中将字符串拆分为数组?
- docker - 使用 Skopeo 检查本地图像
- javascript - 从对象数组返回最小值
- powerapps - 在 Powerapps 门户中找不到 Common Data Service 的依赖项
- android - 当我尝试删除 List Element-Android Studio 时应用程序崩溃
- python - Yfinance Pandas 挑选原始或 fmt 值