Javascript 在HTML中调整表的列
我想要一个表格,这样如果页面宽度减小,表格的列应该一列一列地显示出来。好的,如果我理解正确,你想要这样的东西: 此解决方案将使您的桌子具有响应性,因此它可以做您想做的事情(至少我知道您想做什么) 只是一些示例html代码Javascript 在HTML中调整表的列,javascript,html,angularjs,Javascript,Html,Angularjs,我想要一个表格,这样如果页面宽度减小,表格的列应该一列一列地显示出来。好的,如果我理解正确,你想要这样的东西: 此解决方案将使您的桌子具有响应性,因此它可以做您想做的事情(至少我知道您想做什么) 只是一些示例html代码 <h1>RWD List to Table</h1> <table class="rwd-table"> <tr> <th>Movie Title</th> <th>Gen
<h1>RWD List to Table</h1>
<table class="rwd-table">
<tr>
<th>Movie Title</th>
<th>Genre</th>
<th>Year</th>
<th>Gross</th>
</tr>
<tr>
<td data-th="Movie Title">Star Wars</td>
<td data-th="Genre">Adventure, Sci-fi</td>
<td data-th="Year">1977</td>
<td data-th="Gross">$460,935,665</td>
</tr>
<tr>
<td data-th="Movie Title">Howard The Duck</td>
<td data-th="Genre">"Comedy"</td>
<td data-th="Year">1986</td>
<td data-th="Gross">$16,295,774</td>
</tr>
<tr>
<td data-th="Movie Title">American Graffiti</td>
<td data-th="Genre">Comedy, Drama</td>
<td data-th="Year">1973</td>
<td data-th="Gross">$115,000,000</td>
</tr>
</table>
希望这能帮助您您可以使用CSS显示属性来改变表的行为方式。为了使表格单元格彼此重叠,您需要创建一个媒体查询,将表格和每个单元格设置为在最适合您需要的断点处显示:block 在下面的示例中,当屏幕宽度缩小到500px时,表格单元格将自动换行 例子
@介质(最大宽度:500px){
桌子{
显示:块;
边框:实心1px#f00;
}
表td{
显示:块;
边框:实心1px#f00;
}
}
第1栏
第2栏
您能提供一个代码片段或一个到JSFIDLE的链接吗?不,您不能对表列这样做。请改为使用div,使其环绕以满足视口宽度。bbh查看我的awnser它可能只使用bootstrap:getbootstrap。com@lain老实说,我不是。我的答案是基于问题中提供的有限信息,其中没有提及表格标题。事实上,问题既不包括也不排除标题。然而,我的问题更多的是出于好奇:)@lain我认为最好是为他/她指明正确的方向,而不是提供一个可能不符合他需要的具体例子。至少在具备基本知识的情况下,他/她可以自己找到解决方案。
@import "compass/css3";
// More practical CSS...
// using mobile first method (IE8,7 requires respond.js polyfill https://github.com/scottjehl/Respond)
$breakpoint-alpha: 480px; // adjust to your needs
.rwd-table {
margin: 1em 0;
min-width: 300px; // adjust to your needs
tr {
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
}
th {
display: none; // for accessibility, use a visually hidden method here instead! Thanks, reddit!
}
td {
display: block;
&:first-child {
padding-top: .5em;
}
&:last-child {
padding-bottom: .5em;
}
&:before {
content: attr(data-th)": "; // who knew you could do this? The internet, that's who.
font-weight: bold;
// optional stuff to make it look nicer
width: 6.5em; // magic number :( adjust according to your own content
display: inline-block;
// end options
@media (min-width: $breakpoint-alpha) {
display: none;
}
}
}
th, td {
text-align: left;
@media (min-width: $breakpoint-alpha) {
display: table-cell;
padding: .25em .5em;
&:first-child {
padding-left: 0;
}
&:last-child {
padding-right: 0;
}
}
}
}
// presentational styling
@import 'http://fonts.googleapis.com/css?family=Montserrat:300,400,700';
body {
padding: 0 2em;
font-family: Montserrat, sans-serif;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
color: #444;
background: #eee;
}
h1 {
font-weight: normal;
letter-spacing: -1px;
color: #34495E;
}
.rwd-table {
background: #34495E;
color: #fff;
border-radius: .4em;
overflow: hidden;
tr {
border-color: lighten(#34495E, 10%);
}
th, td {
margin: .5em 1em;
@media (min-width: $breakpoint-alpha) {
padding: 1em !important;
}
}
th, td:before {
color: #dd5;
}
}