html5中table怎么⾃动缩放,Table⾃适应样式HTML响应式表格
(Respons。。。
简单⾃适应表格
简单⾃适应 Table ,通过给表格的外⾯加了⼀个 .table-container 的标签。 CSS 样式如下:
.table-container
{
width: 100%;
overflow-y: auto;
_overflow: auto;
margin: 0 0 1em;
}
table{border:0; border-collapse:collapse;}
table td,table th{border:1px solid #999; padding:.5em 1em}
//添加IOS下滚动条
.table-container::-webkit-scrollbar
{
-webkit-appearance: none;
width: 14px;
height: 14px;
}
.table-container::-webkit-scrollbar-thumb
{
html网页设计 table border-radius: 8px;
border: 3px solid #fff;
background-color: rgba(0, 0, 0, .3);
}
Bootstrap3 ⾃适应表格
Bootstrap3.0 也类似这样⼦的简单⾃适应,当屏幕⼩于767像素时,表格就会⾃适应,多的隐藏可以滚动。需要 Bootstrap 框架⽀持。@media (max-width: 767px) {
.table-responsive {
width: 100%;
margin-bottom: 15px;
overflow-x: scroll;
overflow-y: hidden;
border: 1px solid #dddddd;
-ms-overflow-style: -ms-autohiding-scrollbar;
-webkit-overflow-scrolling: touch;
}
.table-responsive > .table {
margin-bottom: 0;
}
.table-responsive > .table > thead > tr > th,
.table-responsive > .table > tbody > tr > th,
.table-responsive > .table > tfoot > tr > th,
.table-responsive > .table > thead > tr > td,
.
table-responsive > .table > tbody > tr > td,
.table-responsive > .table > tfoot > tr > td {
white-space: nowrap;
}
隐藏表格栏⽬
随着屏幕宽度变⼩⽽删除⼀些内容。出处:点击这⾥
@media only screen and (max-width: 800px) {
#unseen table td:nth-child(2),
#unseen table th:nth-child(2) {display: none;}
}
@media only screen and (max-width: 640px) {
#unseen table td:nth-child(4),
#unseen table th:nth-child(4),
#unseen table td:nth-child(7),
#unseen table th:nth-child(7),
#unseen table td:nth-child(8),
#unseen table th:nth-child(8){display: none;}
}
翻转滚动表格
当屏幕宽度⼩于800时,表格内容则会发⽣翻转,表头的内容会放在左边。右边则是会出现滚动,超出的隐藏。这个要求是表格⽐较完整,不然不是很好看。在表格的外⾯加个#flip-scroll,该技术来源于这⾥
table tr td, table tr th{white-space:nowrap;}
@media only screen and (max-width: 800px) {
#flip-scroll .cf:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
#flip-scroll * html .cf { zoom: 1; }
#flip-scroll *:first-child+html .cf { zoom: 1; }
#flip-scroll table { width: 100%; border-collapse: collapse; border-spacing: 0; }
#flip-scroll th,
#flip-scroll td { margin: 0; vertical-align: top; }
#flip-scroll th { text-align: left; }
#flip-scroll table { display: block; position: relative; width: 100%; }
#flip-scroll thead { display: block; float: left; }
#flip-scroll tbody { display: block; width: auto; position: relative; overflow-x: auto; white-space: nowrap; } #flip-scroll thead tr { display: block; }
#flip-scroll th { display: block; text-align: right; }
#flip-scroll tbody tr { display: inline-block; vertical-align: top; }
#flip-scroll td { display: block; min-height: 1.25em; text-align: left; }
/* sort out borders */
#flip-scroll th { border-bottom: 0; border-left: 0; }
#flip-scroll td { border-left: 0; border-right: 0; border-bottom: 0; }
#flip-scroll tbody tr { border-left: 1px solid #babcbf; }
#flip-scroll th:last-child,
#flip-scroll td:last-child { border-bottom: 1px solid #babcbf; }
}
演⽰截图如下:
相对⾃适应表格
左边的表头名⼀列不滚动,右边的数据内容超出要滚动。源码:GitHub
table{border-collapse:collapse; border-spacing:0; border:0;width:100%;}
table tr td, table tr th{border:1px solid #999; padding:.5em 1em; white-space:nowrap;}
.table-first tr th, .table-first tr td{background:#F4F4F4; font-weight:bold;}
.
table-container table tr td, .table-container tr th{border:0; border-bottom:1px solid #999; border-right:1px solid #999; text-align:center;}
.table-container table{border:1px solid #999; border-left:0;}
.table-two{position:relative;}
/*左边内容是表头名的宽度,根据实际情况⽽定,你也可以使⽤百分⽐*/
.table-first{position:absolute; left:0; top:0; width:102px;/*width:20%;*/}
/*距离左边表头的内容宽度*/
.table-second{padding-left:102px;/*width:20%*/}
/*超出部分出现滚动条*/
.table-container{width:100%; overflow-y:auto; _overflow:auto; margin:0 0 1em;}
/*IOS滚动条*/
.table-container::-webkit-scrollbar
{
-webkit-appearance: none;
width: 14px;
height: 14px;
}
.table-container::-webkit-scrollbar-thumb
{
border-radius: 8px;
border: 3px solid #fff;
background-color: rgba(0, 0, 0, .3);
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论