当前位置:网站首页>Table responsive layout tips for super nice
Table responsive layout tips for super nice
2022-06-30 15:51:00 【Sb_ Coco】
today , I met a very interesting question , A group friend asked me , Only use CSS, Whether such a responsive layout effect can be achieved :
Simply analyze the effect :
- When the screen viewport is wide , As a whole Table The style of
- When the screen viewport width is small , primary Table Each row of data in the is split into one Table To display
An interesting responsive layout , Let the information get a good display under the small screen .
that , Only use CSS Words , Can such a layout be realized ? The answer is Tolerable .
First , It will definitely use Media query , It's not hard to see that . in addition , Let's look at each set of data after splitting :
There will be a group of the original whole Table Header information when , The main difficulty is here , How do we split it into sub - items one by one Table Display time , At the same time, these header information ?
Implementation of the basic structure
First , Let's first implement the... Under the conventional widescreen HTML And the corresponding CSS.
Relatively simple , There is nothing special here , Use <table> Label or use div、ul Wait for the tag to simulate a table .
<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>
// ... Repeat groups
</tbody>
</table>Get such a simple Table:
Use media query to put a single Table Split into multiple
The next step is simple , Set the appropriate threshold ( It depends on the actual business situation ), Use media query to put a single Table Split into multiple children Table.
@media screen and (max-width: 600px) {
table {
border: 0;
}
table thead {
display: none;
}
table tr {
display: block;
margin-bottom: 10px;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
}
}What is done here is also very simple :
- Use the media to search , Set the screen width to be less than
600pxThe style of - Remove from the original table
<thead>Header , Just hide it - Put the original line
<tr>, Set todisplay: block, And set a bottom margin , Make each of them separate - In the original line
<td>, Set todisplay: block, such , They will be arranged vertically , Make every one<tr>Form a new child table
good , such , Then the screen width is less than 600px when , We got this one Table:
With the help of pseudo elements and their properties , Display header information
Next step , That is the most critical step , How do we get there table Each line , That is to say <td> Inside , Show the original header information ?
It's actually very simple here , It simply uses pseudo elements , Extremely readable HTML Small feature implementation of tag attributes .
We just need to make a simple change to the code , For each <td> Of HTML, Bring the corresponding header column description information :
<table>
// The information above is consistent
<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 scope="row" data-label="Account">Visa - 6076</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Amount">$2,443</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
</tr>
// ... Every tr Do the same
</tbody>
</table>next , With the help of td The pseudo elements of , Display the header information :
@media screen and (max-width: 600px) {
// ... bring into correspondence with
table td {
position: relative;
display: block;
text-align: right;
}
table td::before {
position: absolute;
left: 10px;
right: 0;
content: attr(data-label);
}
} here , Our core knowledge point is to use the pseudo element of the element to be able to content In the attribute , Read it HTML Attribute contents within the element , And show the knowledge points .
- Suppose a HTML Labels are defined as :
<div data-msg="ABC"> - Then the div If the corresponding pseudo class is set
content: attr(data-msg), You can read data-msg Value , amount tocontent:"ABC"
such , We are on a small screen , You get such an effect :
The complete effect , As shown in the caption :
complete DEMO, You can poke here :CodePen Demo -- Simple Responsive Table in CSS
Last
This feature of pseudo elements can be applied in many places in daily effects , There are many articles mentioned before .
A very small skill , Have you learned ? This concludes the article , I hope it helps you
More exciting CSS Technical articles summarized in mine Github -- iCSS , Continuous updating , Welcome to point a star Subscribe to the collection .
Any questions or Suggestions , Communicate more , Original article , Writing co., LTD. , Pretty good , If there is anything wrong with the text , All hope to inform .
边栏推荐
- 服务端测试工程师面试经验
- Is Domain Driven Design (DDD) reliable?
- Policy Center > Misrepresentation
- Teach you a learning method to quickly master knowledge
- My own opinion on lisp
- 【Unity UGUI】ScrollRect 动态缩放格子大小,自动定位到中间的格子
- What would you choose between architecture optimization and business iteration?
- Interview experience of service end test engineer
- 技不压身,快速入门ETH智能合约开发,带你进入ETH世界
- Parameter optimization - bias and variance
猜你喜欢

Map reduce case super detailed explanation

Talk about why I started technical writing
![[附下载]渗透测试神器Nessus安装及使用](/img/ef/b6a37497010a8320cf5a49a01c2dff.png)
[附下载]渗透测试神器Nessus安装及使用

Alibaba cloud OSS object storage cross domain settings

What would you choose between architecture optimization and business iteration?

《网络是怎么样连接的》读书笔记 - 汇总篇

Policy Center > Malware > Malware

Modifying MySQL password under Linux: error 1396 (HY000): Operation alter user failed for 'root' @ 'localhost‘

Kubernetes: a comprehensive analysis of container choreography

Policy Center > Malware > Malware
随机推荐
爬虫(1) - 爬虫基础入门理论篇
Create a new MySQL database under Linux and import SQL files
实时渲染和预渲染有什么区别
阿里云oss对象存储跨域设置
Smart wind power: operation and maintenance of digital twin 3D wind turbine intelligent equipment
halcon变量窗口的图像变量不显示,重启软件和电脑都没用
Teach you a learning method to quickly master knowledge
Openresty built in variable
Warning: [antd: Menu] `children` will be removed in next major version. Please use `items` instead.
The difference between intermodulation and intermodulation
Kubernetes: a comprehensive analysis of container choreography
mysql主从配置
KDD 2022 | 我们离通用预训练推荐模型还有多远?推荐系统的通用序列表示学习模型 UniSRec
openresty 内置变量
[sub matrix quantity statistics] cf1181c flag sub matrix quantity statistics
Policy Center > Deceptive Behavior
Compare whether the two arrays are the same
ASP. Net core signalr tutorial
Google Play 索引表
Visualization of provincial GDP with CSV metabase processing