html - table is not being responsive with css properly on smaller devices?
问题描述
I am coming to a problem where I am trying to make my table responsive. It work in this case but table-layout: fixed;
make it worked but, when I resize my columns get together. I use word-break: break-word;
but it just made my text squished. When I comment the table-layout:fixed
and resize browser it gets my data crushed. How to make it responsive in my code below. thanks for the help.
Here is my code:
table {
table-layout: fixed;
margin: auto;
}
th,
td {
padding: 5px 10px;
}
thead,
tfoot {
background: #f9f9f9;
display: table;
width: 100%;
width: calc(100% - 18px);
}
tbody {
overflow: auto;
overflow-x: hidden;
display: block;
width: 100%;
}
tbody tr {
display: table;
width: 100%;
table-layout: fixed;
word-break: break-word
}
<table>
<tbody>
<tr>
<th></th>
<th class="right-header">Step 1</th>
<th class="right-header">Step 2</th>
<th class="right-header">Step 3</th>
<th class="right-header">Step 4</th>
<th class="right-header">Step 5</th>
<th class="right-header">Step 6</th>
<th class="right-header">Step 7</th>
<th class="right-header">Step 8</th>
</tr>
<tr class="odd">
<td class="left-header">Test</td>
<td class="left-header"> $57.36</td>
<td class="left-header"> $58.94</td>
<td class="left-header"> $60.56</td>
<td class="left-header"> $62.23</td>
<td class="left-header"> $65.70</td>
<td class="left-header"> $69.37</td>
<td class="left-header"> $73.23</td>
<td class="left-header"> $77.31</td>
</tr>
<tr class="odd">
<td class="left-header">Test</td>
<td class="left-header"> $4,588.80</td>
<td class="left-header"> $4,715.20</td>
<td class="left-header"> $4,844.80</td>
<td class="left-header"> $4,978.40</td>
<td class="left-header"> $5,256.00</td>
<td class="left-header"> $5,549.60</td>
<td class="left-header"> $5,858.40</td>
<td class="left-header"> $6,184.80</td>
</tr>
<tr class="odd">
<td class="left-header">Test</td>
<td class="left-header"> $119,767.68</td>
<td class="left-header"> $123,066.72</td>
<td class="left-header"> $126,449.28</td>
<td class="left-header"> $129,936.24</td>
<td class="left-header"> $137,181.60</td>
<td class="left-header"> $144,844.56</td>
<td class="left-header"> $152,904.24</td>
<td class="left-header"> $161,423.28</td>
</tr>
</tbody>
</table>
解决方案
这种长列是没有办法的。对于响应式布局,您必须重新考虑一些不同的东西(可能是用相关标题堆叠列)。它同样适用于 html 电子邮件。
推荐阅读
- laravel - 使用 GUZZLE 客户端 LARAVEL 发布 XML
- uvm - 为什么 uvm_top 消失了?
- python - 我有一个 .csv 文件,其中包含图的边缘(Name1,Name2)。如何将其转换为邻接矩阵?
- javascript - 在 Typescript 中使用 Edge.js 调用 API
- reactjs - 为什么当 subscribeHeaders 没有从“react-stomp”库中将道具传递给 SockJsClient 时,所有主题都获得相同的 id
- android - 如何解析多种单键的响应
- applescript - 将文件插入文件夹
- python - 如何使用 Django 将数据从谷歌图书 API 发布到您的图书模型
- php - 如何查询数据库列名?
- java - 如何根据语言环境从 String 中获取 Double?