响应表引导程序隐藏列

时间:2016-11-02 05:26:26

标签: java html css twitter-bootstrap

我想在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

**

  

在移动视图中,我想删除X TITLE,该怎么做?

**

提前致谢

1 个答案:

答案 0 :(得分:0)

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>