gpt4 book ai didi

html - 制作宽表,在移动设备上折叠成行

转载 作者:行者123 更新时间:2023-11-28 04:50:31 26 4
gpt4 key购买 nike

我们有一些具有不同表数据的产品数据。有时有 2 列,然后可能有 4 列。当有 4 列时,它会在移动设备上引起问题并且不适合我们的响应式布局。

任何人都可以帮助让表格在移动设备上更好地工作。

这是原始表格:https://jsfiddle.net/Lnjsv48g/

我正在使用的指南:https://css-tricks.com/examples/ResponsiveTables/responsive.php

这是我的响应尝试:https://jsfiddle.net/f1z6czeo/

<table align="center" border="2" style="height:445px; width:761px">
<caption>Technical Information</caption>
<tbody>
<tr>
<td>Washer Speeds</td>
<td>Speed 1</td>
<td>Speed 2</td>
<td>Speed 3</td>
</tr>
<tr>
<td>Revs per minute squared</td>
<td>480m³/hr</td>
<td>600m³/hr</td>
<td>950³/hr</td>
</tr>
<tr>
<td>Extraction Rate ³/hr Recirculated</td>
<td>322m³/hr</td>
<td>402m³/hr</td>
<td>636m³/hr</td>
</tr>
<tr>
<td>Noise Levels DB/A</td>
<td>54 DB</td>
<td>57 DB</td>
<td>63 DB</td>
</tr>
<tr>
<td>Minimum Height of Product</td>
<td>No Less Than 650mm From Your Base</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>DPP Rating</td>
<td>D</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Backup Filter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Optional Extra)</td>
<td>Round 5 (2 Filters required)</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Light Options</td>
<td>2x 1.2w LED Bulk BBT299</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Marble Size &nbsp; &nbsp; &nbsp; &nbsp; (Marble Kit optional Extra)</td>
<td>125mm Minimum(150mm is recommended)(Up to 4 Mtr&nbsp;&nbsp; Only)</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Remote Control</td>
<td>No</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Warranty &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; (Subject to registration)</td>
<td>3 years</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>BPP Scheme Colour Code</td>
<td>N/A</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>BOR Rand Filters&nbsp;&nbsp;&nbsp; (Cleaner Safe)</td>
<td>Y</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Box Type</td>
<td>3 Amp</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Gang Type</td>
<td>Toggle Control</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<table border="0" style="height:82px; width:273px">
<tbody>
<tr>
<td><a href="/Installation Instruction.pdf" target="_blank" title="60cm curved glass cooker hoods tech sheet"><img alt="pdf icon" src="https://s18.postimg.org/wlzpg6c21/PDF_Logo_2.png" style="float:left; height:75px; margin-right:20px; width:75px"></a></td>
<td>Installation Guide<br>
PDF File - Opens in a New Window</td>
</tr>
</tbody>
</table>
</td>
<td>
<table border="0">
<tbody>
<tr>
<td><a href="/install_guide.pdf" target="_blank" title="60cm curved glass cooker hoods tech sheet"><img alt="pdf icon" src="https://s18.postimg.org/wlzpg6c21/PDF_Logo_2.png" style="float:left; height:75px; margin-right:20px; width:75px"></a></td>
<td>Product Specification Guide<br>
PDF File - Opens in a New Window</td>
</tr>
</tbody>
</table>
</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>

最佳答案

这是一个解决方案:查看代码片段

@media only screen and (max-width: 760px){

table {
width: 100%;
border-collapse: collapse;
border: none;
}

table, thead, tbody, th {
display: block;
}
tbody, td, tr {
display: inline-block;
}

thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
tr.techinfo {
border: 1px solid #aaa;
width: 100%;
background: #eee;
box-sizing: border-box;
}
.techinfo > td {
float: right;
width: 60%;
display: inline-block;
background: #eee;
padding-left: 3px;
border: none;
box-sizing: border-box;
overflow: hidden;
white-space: nowrap;
}
.techinfo > td:first-child {
width: 39%;
float: left;
line-height: 4em;
}
.techinfo > td:nth-child(2){
background: #bbb;
}
.techinfo > td:nth-child(3){
background: #ccc;
}
.techinfo > td:nth-child(4){
background: #ddd;
}
.docs {
width: 100%;
border: none;
}

.docs > td {
width: 100%;
box-sizing: border-box;
background-color: #eee;
}
.docs > td > table {
box-sizing: border-box;
padding: 0 3px;
}
.docs > td tr {
border: none;
box-sizing: border-box;
}
}
<table align="center" border="2">
<caption>Technical Information</caption>
<tbody>
<tr class="techinfo">
<td>Washer Speeds</td>
<td>Speed 1</td>
<td>Speed 2</td>
<td>Speed 3</td>
</tr>
<tr class="techinfo">
<td>Revs per minute squared</td>
<td>480m³/hr</td>
<td>600m³/hr</td>
<td>950³/hr</td>
</tr>
<tr class="techinfo">
<td>Extraction Rate ³/hr Recirculated</td>
<td>322m³/hr</td>
<td>402m³/hr</td>
<td>636m³/hr</td>
</tr>
<tr class="techinfo">
<td>Noise Levels DB/A</td>
<td>54 DB</td>
<td>57 DB</td>
<td>63 DB</td>
</tr>
<tr class="techinfo">
<td>Minimum Height of Product</td>
<td>No Less Than 650mm From Your Base</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="techinfo">
<td>DPP Rating</td>
<td>D</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="techinfo">
<td>Backup Filter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Optional Extra)</td>
<td>Round 5 (2 Filters required)</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="techinfo">
<td>Light Options</td>
<td>2x 1.2w LED Bulk BBT299</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="techinfo">
<td>Marble Size (Marble Kit optional Extra)</td>
<td>125mm Minimum(150mm is recommended)(Up to 4 Mtr Only)</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="techinfo">
<td>Remote Control</td>
<td>No</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="techinfo">
<td>Warranty(Subject to registration)</td>
<td>3 years</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="techinfo">
<td>BPP Scheme Colour Code</td>
<td>N/A</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="techinfo">
<td>BOR Rand Filters&nbsp;&nbsp;&nbsp; (Cleaner Safe)</td>
<td>Y</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="techinfo">
<td>Box Type</td>
<td>3 Amp</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="techinfo">
<td>Gang Type</td>
<td>Toggle Control</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="docs">
<td>
<table>
<tbody>
<tr>
<td><a href="/Installation Instruction.pdf" target="_blank" title="60cm curved glass cooker hoods tech sheet"><img alt="pdf icon" src="https://s18.postimg.org/wlzpg6c21/PDF_Logo_2.png" style="float:left; height:75px; margin-right:20px; width:75px"></a></td>
<td>Installation Guide<br>
PDF File - Opens in a New Window</td>
</tr>
</tbody>
</table>
</td>
<td>
<table>
<tbody>
<tr>
<td><a href="/install_guide.pdf" target="_blank" title="60cm curved glass cooker hoods tech sheet"><img alt="pdf icon" src="https://s18.postimg.org/wlzpg6c21/PDF_Logo_2.png" style="float:left; height:75px; margin-right:20px; width:75px"></a></td>
<td>Product Specification Guide<br>
PDF File - Opens in a New Window</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

关于html - 制作宽表,在移动设备上折叠成行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40737675/

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