gpt4 book ai didi

html - 响应式数据表html

转载 作者:搜寻专家 更新时间:2023-10-31 22:57:23 24 4
gpt4 key购买 nike

我有一个 5 列表,在移动设备上,它需要为每一行重复每个标题。

我在互联网上没有任何运气(可能是因为我使用了错误的词来搜索它“每行 html 的重复表标题”)...我找到了一个解决方案,但我已经丢失了,但是代码太多了,太复杂了,难以理解。我正在寻找一些关于我应该如何构建结构的建议/帮助,或者我可能需要做两个完全不同的标记?我也看到了一些插件,但是不让用(我是初级岗位,他们要我自己想办法解决问题)。

我不能提供很多信息......因为我真的不知道该怎么做,但我想这一定是一种不在每一行重复 html 标题的方法......对?

有什么帮助吗?

html:

    <table class="myOrders col-xs-12" border="1">
<thead>
<tr class="headers col-xs-12">
<th class="col-sm-3 col-x-7">ORDER PLACED</th>
<th class="col-sm-2 col-x-7">ORDER ID</th>
<th class="col-sm-2 col-x-7">ORDER REF</th>
<th class="col-sm-3 col-x-7">ORDER AMOUNT</th>
<th class="col-sm-2 col-x-7">STATUS</th>
</tr>
</thead>
<tbody>
<tr class="order col-xs-12">
<td class="datePlaced col-sm-3 col-x-7"><span>2016-05-12</span><span>15.13.56</span></td>
<td class="ident col-sm-2 col-x-7">AW 1234-165</td>
<td class="ref col-sm-2 col-x-7">SMRF123</td>
<td class="amount col-sm-3 col-x-7">£23.33</td>
<td class="status col-sm-2 col-x-7">Pending</td>
</tr>
<tr class="order col-xs-12">
<td class="datePlaced col-sm-3 col-x-7"><span>2016-05-12</span><span>15.13.56</span></td>
<td class="ident col-sm-2 col-x-7">AW 1234-165</td>
<td class="ref col-sm-2 col-x-7">SMRF123</td>
<td class="amount col-sm-3 col-x-7">£23.33</td>
<td class="status col-sm-2 col-x-7">Pending</td>
</tr>
<tr class="order col-xs-12">
<td class="datePlaced col-sm-3 col-x-7"><span>2016-05-12</span><span>15.13.56</span></td>
<td class="ident col-sm-2 col-x-7">AW 1234-165</td>
<td class="ref col-sm-2 col-x-7">SMRF123</td>
<td class="amount col-sm-3 col-x-7">£23.33</td>
<td class="status col-sm-2 col-x-7">Pending</td>
</tr>
</tbody>
</table>

CSS:

table td[class*="col-"], 
table th[class*="col-"] {
float: left;
}

这是期望的行为: enter image description here

https://jsfiddle.net/zzxac8ew/

最佳答案

使用 data-thTD

@media screen and (max-width: 640px) {
table#customDataTable caption {
background-image: none;
}

table#customDataTable thead {
display: none;
}

table#customDataTable tbody td {
display: block;
padding: .6rem;
}

table#customDataTable tbody tr td:first-child {
background: #666;
color: #fff;
}

table#customDataTable tbody tr td:first-child a {
color: #fff;
}

table#customDataTable tbody tr td:first-child:before {
color: rgb(225,181,71);
}

table#customDataTable tbody td:before {
content: attr(data-th);
font-weight: bold;
display: inline-block;
width: 10rem;
}

table#customDataTable tr th:last-child, table#customDataTable tr td:last-child {
max-width: 100% !important;
min-width: 100px !important;
width: 100% !important;
}
}
       <table id="customDataTable" class="myOrders col-xs-12" border="1">
<thead>
<tr class="headers col-xs-12">
<th class="col-sm-3 col-x-7">ORDER PLACED</th>
<th class="col-sm-2 col-x-7">ORDER ID</th>
<th class="col-sm-2 col-x-7">ORDER REF</th>
<th class="col-sm-3 col-x-7">ORDER AMOUNT</th>
<th class="col-sm-2 col-x-7">STATUS</th>
</tr>
</thead>
<tbody>
<tr class="order col-xs-12">
<td data-th="ORDER PLACED" class="datePlaced col-sm-3 col-x-7"><span>2016-05-12</span><span>15.13.56</span></td>
<td data-th="ORDER ID" class="ident col-sm-2 col-x-7">AW 1234-165</td>
<td data-th="ORDER REF" class="ref col-sm-2 col-x-7">SMRF123</td>
<td data-th="ORDER AMOUNT" class="amount col-sm-3 col-x-7">£23.33</td>
<td data-th="STATUS" class="status col-sm-2 col-x-7">Pending</td>
</tr>
<tr class="order col-xs-12">
<td data-th="ORDER PLACED" class="datePlaced col-sm-3 col-x-7"><span>2016-05-12</span><span>15.13.56</span></td>
<td data-th="ORDER ID" class="ident col-sm-2 col-x-7">AW 1234-165</td>
<td data-th="ORDER REF" class="ref col-sm-2 col-x-7">SMRF123</td>
<td data-th="ORDER AMOUNT" class="amount col-sm-3 col-x-7">£23.33</td>
<td data-th="STATUS" class="status col-sm-2 col-x-7">Pending</td>
</tr>
<tr class="order col-xs-12">
<td data-th="ORDER PLACED" class="datePlaced col-sm-3 col-x-7"><span>2016-05-12</span><span>15.13.56</span></td>
<td data-th="ORDER ID" class="ident col-sm-2 col-x-7">AW 1234-165</td>
<td data-th="ORDER REF" class="ref col-sm-2 col-x-7">SMRF123</td>
<td data-th="ORDER AMOUNT" class="amount col-sm-3 col-x-7">£23.33</td>
<td data-th="STATUS" class="status col-sm-2 col-x-7">Pending</td>
</tr>
</tbody>
</table>

https://jsfiddle.net/zzxac8ew/1/

关于html - 响应式数据表html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38973566/

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