gpt4 book ai didi

java - 响应式表 Bootstrap 隐藏列

转载 作者:太空宇宙 更新时间:2023-11-04 12:05:50 24 4
gpt4 key购买 nike

我想在 Bootstrap 中使用响应式表格,但我的代码有问题,可能无法正常工作。

这是我的代码:

table { 
width: 100%;
border-collapse: collapse;
}
/* Zebra striping */
tr:nth-of-type(odd) {
background: #eee;
}
th {
background: #333;
color: white;
font-weight: bold;
}
td, th {
padding: 6px;
border: 1px solid #ccc;
text-align: left;
}
@media
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {

/* Force table to not be like tables anymore */
table, thead, tbody, th, td, tr {
display: block;
}

/* Hide table headers (but not display: none;, for accessibility) */
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}

tr { border: 1px solid #ccc; }

td {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
}

td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
}
<table class="table table-responsive">
<thead>
<tr>
<th>X Title</th>
<th>Y Title</th>
<th>Z Title</th>
</tr>
</thead>
<tbody>
<tr>
<td> XXX </td>
<td> YYY </td>
<td> ZZZ </td>
</tr>
</tbody>
</table>

有些东西我不知道如何让它像下图一样仅在移动或小屏幕尺寸下工作:

Mobile View

**

In mobile view I want to remove X TITLE, how to do it?

**

提前致谢

最佳答案

Please follow the link

http://codepen.io/srees/pen/KNPPJy?editors=1100

Hope you got the answer

body {
padding:1.5em;
background: #f5f5f5;
}

table {
border: 1px #a39485 solid;
font-size: .9em;
box-shadow: 0 2px 5px rgba(0,0,0,.25);
width: 100%;
border-collapse: collapse;
border-radius: 5px;
overflow: hidden;
}

th {
text-align: left;
}

thead {
font-weight: bold;
color: #000;
background: #d5d5d5;
}

td, th {
padding: 1em .5em;
vertical-align: middle;
}

td {
border-bottom: 1px solid rgba(0,0,0,.1);
background: #fff;
}

a {
color: #73685d;
}

@media all and (max-width: 768px) {

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

th {
text-align: right;
}

table {
position: relative;
padding-bottom: 0;
border: none;
box-shadow: 0 0 10px rgba(0,0,0,.2);
}

thead {
float: left;
white-space: nowrap;
}

tbody {
overflow-x: auto;
overflow-y: hidden;
position: relative;
white-space: nowrap;
}

tr {
width: 100%;
display: inline-block;
vertical-align: top;
}

th {
border-bottom: 1px solid #f5f5f5;
}

td {
border-bottom: 1px solid #e5e5e5;
}


}
<table class="table table-responsive">
<thead>
<tr>
<th>X Title</th>
<th>Y Title</th>
<th>Z Title</th>
</tr>
</thead>
<tbody>
<tr>
<td> XXX </td>
<td> YYY </td>
<td> ZZZ </td>
</tr>
</tbody>
</table>

关于java - 响应式表 Bootstrap 隐藏列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40373024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com