【发布时间】:2020-07-20 07:46:56
【问题描述】:
我有以下 HTML 表格
<table>
<tr>
<td>Cell 1.1</td>
<td>Cell 1.2</td>
<td>Cell 1.3</td>
</tr>
<tr>
<td>Cell 2.1</td>
<td>Cell 2.2</td>
<td>Cell 2.3</td>
</tr>
<tr>
<td>Cell 3.1</td>
<td>Cell 3.2</td>
<td>Cell 3.3</td>
</tr>
</table>
上表自然显示如下
----------------------------------
| Cell 1.1 | Cell 1.2 | Cell 1.3 |
----------------------------------
| Cell 2.1 | Cell 2.2 | Cell 2.3 |
----------------------------------
| Cell 3.1 | Cell 3.2 | Cell 3.3 |
----------------------------------
所以我喜欢做的是创建一个响应式设计,这样当网页在桌面屏幕上查看时,表格显示如上,但是当网页在手机屏幕上查看时,表格如下图所示
------------
| Cell 1.1 |
------------
| Cell 2.1 |
------------
| Cell 3.1 |
------------
------------
| Cell 1.2 |
------------
| Cell 2.2 |
------------
| Cell 3.3 |
------------
------------
| Cell 1.3 |
------------
| Cell 2.3 |
------------
| Cell 3.3 |
------------
我喜欢只使用 CSS 来实现上述目标。它应该看起来像这样
/* CSS RULES FORE MOBILE */
/* Add here CSS code that makes the table traverse vertically */
@media screen and (min-width: 1280) {
/* CSS RULES FORE DESKTOP */
/* Rest CSS rules, to display the table for desktop */
}
我不知道该怎么做,或者完全不知道如何处理这件事。感谢您的帮助。谢谢。
【问题讨论】:
-
我怀疑您是否可以单独使用表格标签和 CSS 来实现这一点,因为您可以通过
tr标签明确按行分组。如果您可以放弃table标签的语义,CSS Grid 在这里可能会有所帮助。 -
@JonP - 嗯,我会试试的。感谢您的提示。
标签: html css html-table responsive-design responsive