我正在尝试使用“无更多表”方法制作响应表。
我只是复制并粘贴了上面示例中的代码。它可以在JSFiddle上正常工作:http : //jsfiddle.net/wcp62x7t/
但是在我的浏览器中使用相同的代码无法正常工作。当我减小浏览器窗口的大小时,这些表的表现不佳:
我究竟做错了什么?这是我在浏览器中尝试的完整HTML文件:我已经在Safari和OSX上的Chrome浏览器中进行了尝试,并得到了上面提到的奇怪行为。
<html>
<head>
<style>
@media only screen and (max-width: 800px) {
/* Force table to not be like tables anymore */
#no-more-tables table,
#no-more-tables thead,
#no-more-tables tbody,
#no-more-tables th,
#no-more-tables td,
#no-more-tables tr {
display: block;
}
/* Hide table headers (but not display: none;, for accessibility) */
#no-more-tables thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
#no-more-tables tr { border: 1px solid #ccc; }
#no-more-tables td {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
white-space: normal;
text-align:left;
}
#no-more-tables td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
text-align:left;
font-weight: bold;
}
/*
Label the data
*/
#no-more-tables td:before { content: attr(data-title); }
}
</style>
</head>
<body>
<section id="no-more-tables">
<table>
<thead>
<tr>
<th>Code</th>
<th>Company</th>
<th class="numeric">Price</th>
<th class="numeric">Change</th>
<th class="numeric">Change %</th>
<th class="numeric">Open</th>
<th class="numeric">High</th>
<th class="numeric">Low</th>
<th class="numeric">Volume</th>
</tr>
</thead>
<tbody>
<tr>
<td data-title="Code">AAC</td>
<td data-title="Company">AUSTRALIAN AGRICULTURAL COMPANY LIMITED.</td>
<td data-title="Price" class="numeric">$1.38</td>
<td data-title="Change" class="numeric">-0.01</td>
<td data-title="Change %" class="numeric">-0.36%</td>
<td data-title="Open" class="numeric">$1.39</td>
<td data-title="High" class="numeric">$1.39</td>
<td data-title="Low" class="numeric">$1.38</td>
<td data-title="Volume" class="numeric">9,395</td>
</tr>
</tbody>
</table>
</section>
</body>
</html>
更新:浏览器中的问题似乎是,即使我已经使用以下方式显式<td>
设置了元素,元素仍然设置为:display: table-cell
display: block
删除媒体查询标签@media only screen and (max-width: 800px) {}
,之后效果很好。
更新:添加<!DOCTYPE html>
解决了问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句