当前位置:网站首页>table通过伪类实现 另类自适应
table通过伪类实现 另类自适应
2022-06-29 02:17:00 【一个假的前端男】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style> * {
padding: 0; margin: 0; box-sizing: border-box; } @media screen and (min-width: 800px) {
table {
width: 100vw; border: 1px solid black; border-collapse: collapse; } tr {
border-bottom: 1px solid black; } td {
text-align: center; } } @media screen and (max-width: 800px) {
table {
border: 0; width: 100vw; } table thead {
display: none; } table tr {
display:block; margin-bottom: 20px; } table td {
border-bottom: 1px solid #ddd; /* position: relative; */ /* display: block; */ /* text-align: right; */ display: flex; justify-content: space-between; } table td::before {
/* position: absolute; */ /* left: 10px; */ content: attr(data-label); font-weight: 600; } } </style>
</head>
<body>
<table>
<caption>Lorem ipsum !</caption>
<thead>
<tr>
<th>Account</th>
<th>Due Date</th>
<th>Amount</th>
<th>Period</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Account">Visa -
3412</td>
<td data-label="Due Date">04/01/2016</td>
<td data-label="Amount">$1,190</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Due Date">04/02/2016</td>
<td data-label="Amount">$1,190</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Due Date">04/02/2016</td>
<td data-label="Amount">$1,190</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
</tbody>
</table>
</body>
</html>

主要实现方法媒体查询 +借助伪元素极其特性,实现表头信息展示
这里 当他满足屏幕小于800时 隐藏表头 然后打碎td 并通过伪类中的content 实现 表头填充
这里,我们核心的知识点就是利用了元素的伪元素可以在 content 属性里,读取其 HTML 元素内的属性内容,并进行展示的知识点。
假设一个 HTML 标签定义为:
那么该 div 对应的伪元素如果设置了 content: attr(data-msg) ,就可以读取到 data-msg 的值,相当于 content:“ABC”
边栏推荐
猜你喜欢

2022.02.15

SystemVerilog structure (I)

如何用项目甘特图,做好项目汇报
![[redis] hash type](/img/8b/2585908318f5fe88b455323d3f392e.png)
[redis] hash type

CTFHub-Web-SQL注入-整数型注入

How to use project Gantt chart to make project report
![[understanding of opportunity -33]: seeing is not necessarily true. Most of the time,](/img/60/703a5bc3038d28bcf812415032f240.jpg)
[understanding of opportunity -33]: seeing is not necessarily true. Most of the time, "seeing is false"

直播预告|SQL也能玩转工业级机器学习?MLOps meetup V3带你一探究竟!

Live broadcast preview | can SQL also play industrial machine learning? Mlops meetup V3 takes you to the bottom!

How to become a senior digital IC Design Engineer (4-5) script: file comparison operation implemented by shell script
随机推荐
项目研发,有哪些好用的免费脑图工具软件
为什么要在网站上安装SSL证书?
[从零开始学习FPGA编程-49]:视野篇 - 芯片是如何被设计出来的?
[redis] list type
什么叫股票线上开户?网上开户安全么?
想请教一下,如何选择券商?现在网上开户安全么?
Eliminate the hover effect when the button is disabled
【Redis】Hash类型
[redis] get to know redis for the first time
Which is the best billing method for okcc call center
Boost the digital economy and face the future office | the launch of the new version of spreadjsv15.0 is about to begin
如何成为一名高级数字 IC 设计工程师(6-5)数字 IC 验证篇:覆盖率收集
Necessary technologies for chip manufacturers (1) Introduction
To apply for a test engineer after years, the resume with high scores should be written like this
When you complain about the roll, others have quietly begun to prepare for the golden three silver four
Koa quick start
Finally got the byte offer. The 25-year-old inexperienced experience in software testing is written to you who are still confused
OpenResty 使用介绍
How to become a senior digital IC Design Engineer (6-7) digital IC Verification: debug skills
【Redis】SortedSet类型