当前位置:网站首页>Table responsive layout tips
Table responsive layout tips
2022-07-02 15:03:00 【zx_ twenty million two hundred and twenty thousand one hundred 】
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 600px The style of
Remove from the original table <thead> Header , Just hide it
Put the original line <tr>, Set to display: block, And set a bottom margin , Make each of them separate
In the original line <td>, Set to display: 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; righht: 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 element is set content: attr(data-msg) , You can read data-msg Value , amount to content:"ABC"
such , We are on a small screen , You get such an effect :
Last
This feature of pseudo elements can be applied in many places in daily effects , A very small skill , Have you learned ?
边栏推荐
- Base64 编码原来还可以这么理解
- Have you learned the wrong usage of foreach
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- LeetCode 2310. 个位数字为 K 的整数之和
- .NET Core 日志系统
- taobao. trade. memo. Add (add remarks to a transaction) interface, Taobao store flag insertion interface, Taobao order flag insertion API interface, oauth2.0 interface
- Points clés de l'examen de principe de compilation pour l'année scolaire 2021 - 2022 [Université chinoise d'outre - mer]
- JMeter script parameterization
- STM32 standard firmware library function name (I)
- 数据库内容输出有问题怎么解决
猜你喜欢
Ad20 cannot select the solution of component packaging in PCB editor
btrace-(字节码)动态跟踪工具
Error: NPM warn config global ` --global`, `--local` are deprecated Use `--location=global` instead.
mathjax 入门(web显示数学公式,矢量的)
Btrace- (bytecode) dynamic tracking tool
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
编译原理课程实践——实现一个初等函数运算语言的解释器或编译器
大顶堆、小顶堆与堆排序
IE 浏览器正式退休
fatal: unsafe repository is owned by someone else 的解决方法
随机推荐
C RichTextBox controls the maximum number of lines displayed
可视化搭建页面工具的前世今生
[apipost] tutorial
数据库内容输出有问题怎么解决
Find the maximum inscribed circle of the contour
2. Const pointer
taobao. trade. Get (get some information of a single transaction), Taobao store order interface, Taobao oauth2.0 interface, Taobao R2 interface code docking and sharing
如何对 TiDB 进行 TPC-C 测试
fatal: unsafe repository is owned by someone else 的解决方法
为什么只会编程的程序员无法成为优秀的开发者?
MFC A对话框调用B对话框函数并传参
Fatal: unsafe repository is owned by someone else
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
用户隐私协议有些汉字编码不规范导致网页显示乱码,需要统一找出来处理一下
MFC timer usage
LeetCode 2310. The number of digits is the sum of integers of K
富文本编辑器添加矢量公式(MathType for TinyMCE ,可视化添加)
Actual combat sharing of shutter screen acquisition
LeetCode_字符串_简单_412.Fizz Buzz
taobao.trades.sold.get-查询卖家已卖出的交易数据(根据创建时间),淘宝店铺卖出订单查询API接口,淘宝R2接口,淘宝oAuth2.0交易接口代码分享