制作一张宽桌子,在移动设备上折叠成行

时间:2016-11-22 09:06:26

标签: html css responsive-design

我们有一些产品数据具有不同的表格数据。有时会有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>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

我建议使用text-align:center代替padding:50%,因为这并不是很好。

也就是说,看起来您的表格会以适当的大小重新渲染。你想要它具体做什么?你可以嘲笑一下&#39;图像?

最后,如果这只是一个学习练习,这可能对你没有帮助,但是存在一个jQuery插件可以做到这一点:tablesaw

答案 1 :(得分:0)

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

@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>