分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

[CSS3] Responsive Table -- no more table

发布时间:2023-09-06 01:43责任编辑:胡小海关键词:CSS

When the screen size is small, we can use "no more table" solution. So instead of render table is row layout, we render it in column layout.

Given the table below:

 <table> ?????<thead> ???????<tr> ?????????<th>Team</th> ?????????<th>1st</th> ?????????<th>2nd</th> ?????????<th>3rd</th> ?????????<th>4th</th> ?????????<th>5th</th> ?????????<th>6th</th> ?????????<th>7th</th> ?????????<th>8th</th> ?????????<th>9th</th> ?????????<th>Final</th> ???????</tr> ?????</thead> ?????<tbody> ???????<tr> ?????????<td data-th="Team">Toronto</td> ?????????<td data-th="1st">0</td> ?????????<td data-th="2nd">0</td> ?????????<td data-th="3rd">0</td> ?????????<td data-th="4th">4</td> ?????????<td data-th="5th">0</td> ?????????<td data-th="6th">1</td> ?????????<td data-th="7th">0</td> ?????????<td data-th="8th">0</td> ?????????<td data-th="9th">0</td> ?????????<td data-th="Final">5</td> ???????</tr> ???????<tr> ?????????<td data-th="Team">San Francisco</td> ?????????<td data-th="1st">0</td> ?????????<td data-th="2nd">0</td> ?????????<td data-th="3rd">0</td> ?????????<td data-th="4th">4</td> ?????????<td data-th="5th">0</td> ?????????<td data-th="6th">0</td> ?????????<td data-th="7th">0</td> ?????????<td data-th="8th">0</td> ?????????<td data-th="9th">0</td> ?????????<td data-th="Final">4</td> ???????</tr> ?????</tbody>

1. Reset table relatede element to block element:

table, thead, tbody, th, td, tr { ?????????display: block; ???????}

2. Remove the thead:

 ???????thead tr { ?????????position: absolute; ?????????top: -9999px; ?????????left: -9999px; ???????}

3. Position layout:

 ??????/*The actually content will be on the right side*/ ??????td { ??????????position: relative; ?????????padding-left: 50%; ????????} ??????????????/*Using data-th to set the value and set position to left*/ ???????td:before { ??????????position: absolute; ?????????left: 6px; ?????????content: attr(data-th); ?????????font-weight: bold; ???????} ???

Full example:

[CSS3] Responsive Table -- no more table

原文地址:https://www.cnblogs.com/Answer1215/p/8455907.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved