gpt4 book ai didi

css - 将固定表格转换为响应式移动表格

转载 作者:行者123 更新时间:2023-11-28 02:51:24 25 4
gpt4 key购买 nike

网址是http://action.news固定宽度表格中有 3 列)

(我删除了按需加载的脚本)使事情变得更容易。谢谢你

我做了什么:在下面添加了这段代码

https://gist.github.com/hkirsman/3002480

根据谷歌说明添加了这个

<meta name=viewport content="width=device-width, initial-scale=1">

我已阅读HTML table with auto-fit for some columns, fixed width for others

但仍然无法使页面适合移动设备,顶部似乎重新对齐

最佳答案

我在 Codepen 上找到了这个例子,所以你可以尝试并根据你的需要进行调整:

这是一些代码

HTML:

<table class="js-table participants-table">
<caption>
<p>Responsive Table</p>
</caption>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Gender</th>
<th>Picture</th>
</tr>
</thead>
<tbody>
<!--filled from javascript-->
</tbody>
</table>

CSS:

HTML {
font-size: 100%;
line-height: 1.5;
font-family: 'Raleway', sans-serif;
}

BODY {
margin: 0;
}

*, *:before, *:after {
box-sizing: border-box;
}

IMG {
max-width: 100%;
}


/*Style For Table*/

.participants-table {
table-layout: fixed;
border-collapse: collapse;
margin: 0 auto;
width: 90%;
}

.participants-table TD,
.participants-table TH {
border: 1px solid #b4adad;
}

.participants-table IMG {
width: 150px;
}

.participants-table THEAD {
display: none;
}

.participants-table TD {
display: block;
position: relative;
overflow-x: hidden;
text-overflow: ellipsis;
}


@media only screen and (min-width: 450px) {
.participants-table {
width: auto;
}
.participants-table TD,
.participants-table TH {
padding: .2em 1em;
}
.participants-table THEAD {
display: table-header-group;
}
.participants-table TD {
display: table-cell;
position: static;
}
.participants-table TD:before {
display: none;
}
}

link to the example

关于css - 将固定表格转换为响应式移动表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46657394/

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