2列の表組み
まずは見本のHTMLコード。
/* HTML */
<table>
<tr>
<th>項目名1</th>
<td>内容1</td>
<tr>
<tr>
<th>項目名2</th>
<td>内容2</td>
<tr>
<tr>
<th>項目名3</th>
<td>内容3</td>
<tr>
</table>
次にCSSだが、レイアウトが変化する際のブレイクポイントを設定してメディアクエリにて分ける。
今回は「768px」で分岐させることにする。
/* CSS */
table { width: 100%; }
th, td {
line-height: 1.6;
padding: .75em 1em;
}
th { background: #f5f5f5; }
/* 768pxまでの表示 */
@media (max-width: 768px) {
table {
border-top: 1px #ccc solid;
border-right: 1px #ccc solid;
border-left: 1px #ccc solid;
}
table th,
table td {
display: block;
border-bottom: 1px #ccc solid;
text-align: center;
}
}
/* 769pxからの表示 */
@media (min-width: 769px) {
table { table-layout: fixed; }
th, td { border: 1px #ccc solid; }
th {
width: 30%; /* 適宜変更 */
text-align: left;
}
}
まとめ
セルをブロックにして上下配置にすることで、狭いスペースでも視認性が良くなる。
万一内容部分に長文が入っても比較的見やすいんじゃないかと。
なお「table-layout:fixed」を入れてあるが、以前 ie で普通のテーブル組が崩れたことがあり、そのためのおまじない。これを指定しておくと「セルの均等割り」もしてくれるので結構便利。





