如何使用css或jquery将其更改为2列或3列,目前在一列中
这里是小提琴的链接。 http://jsfiddle.net/4510f0yx/1/
<table class="items table table-striped table-bordered table-condensed">
<thead>
<tr>
<th id="operations_c0" class="checkbox-column">
<input type="checkbox" id="operations_c0_all" name="operations_c0_all" value="1" class="select-on-check-all">
</th>
<th id="operations_c1">Permissions</th>
</tr>
</thead>
<tbody>
<tr class="">
<td colspan="2" class="extrarow"><strong>Auth :: Permission</strong>
</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_0" value="oAuthOperationCreate" class="select-on-check">
</td>
<td>Create</td>
</tr>
<tr class="even">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_1" value="oAuthOperationRead" class="select-on-check">
</td>
<td>Read</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_2" value="oAuthOperationUpdate" class="select-on-check">
</td>
<td>Update</td>
</tr>
<tr class="even">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_3" value="oAuthOperationDelete" class="select-on-check">
</td>
<td>Delete</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_4" value="oAuthOperationList" class="select-on-check">
</td>
<td>List</td>
</tr>
<tr class="even">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_5" value="oAuthOperationManage" class="select-on-check">
</td>
<td>Manage</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_6" value="oAuthOperationSearch" class="select-on-check">
</td>
<td>Search</td>
</tr>
<tr class="">
<td colspan="2" class="extrarow"><strong>Auth :: Parent</strong>
</td>
</tr>
<tr class="even">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_7" value="oAuthParentCreate" class="select-on-check">
</td>
<td>Create</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_8" value="oAuthParentRead" class="select-on-check">
</td>
<td>Read</td>
</tr>
<tr class="even">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_9" value="oAuthParentUpdate" class="select-on-check">
</td>
<td>Update</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_10" value="oAuthParentDelete" class="select-on-check">
</td>
<td>Delete</td>
</tr>
<tr class="even">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_11" value="oAuthParentList" class="select-on-check">
</td>
<td>List</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_12" value="oAuthParentManage" class="select-on-check">
</td>
<td>Manage</td>
</tr>
<tr class="even">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_13" value="oAuthParentSearch" class="select-on-check">
</td>
<td>Search</td>
</tr>
<tr class="">
<td colspan="2" class="extrarow"><strong>Auth :: Role</strong>
</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_14" value="oAuthRoleCreate" class="select-on-check">
</td>
<td>Create</td>
</tr>
<tr class="even">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_15" value="oAuthRoleRead" class="select-on-check">
</td>
<td>Read</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_16" value="oAuthRoleUpdate" class="select-on-check">
</td>
<td>Update</td>
</tr>
<tr class="even">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_17" value="oAuthRoleDelete" class="select-on-check">
</td>
<td>Delete</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_18" value="oAuthRoleList" class="select-on-check">
</td>
<td>List</td>
</tr>
<tr class="even">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_19" value="oAuthRoleManage" class="select-on-check">
</td>
<td>Manage</td>
</tr>
<tr class="odd">
<td class="checkbox-column">
<input type="checkbox" name="AuthItem[seltedOperations][]" id="operations_c0_20" value="oAuthRoleSearch" class="select-on-check">
</td>
<td>Search</td>
</tr>
</tbody>
</table>
答案 0 :(得分:1)
使用它:
table.items {column-count: 2;-moz-column-count: 2;-webkit-column-count: 3;
width: 300px;height: 272px;display: table-cell;}
但它不适用于IEp>
答案 1 :(得分:1)
这里有一些让你入门的东西
<强> CSS 强>
table, thead, tbody, tr, th, td {
display: block;
text-align: left;
}
table, thead, tbody {
width: 100%;
}
tr {
position: absolute;
}
tr:after {
content:' ';
display: block;
clear: both;
}
td, th {
float: left;
}
<强>的jQuery 强>
$(function () {
var left = -1;
var top = 0;
$('tr').each(function () {
var extrarow = $('td', this).hasClass('extrarow');
top += $('td',this).first().height();
if(extrarow) {
left += 1;
top = 0;
}
$(this).css({
width: '33.33%',
top: top,
'left': (left * 33.33) + '%'
});
});
});
示例强>
在 JSFIDDLE
上它有一些已知的错误,就像没有包含标题一样,但你应该可以从中获得完整的解决方案。
答案 2 :(得分:1)
我真的认为你需要用框架中的3列构建你的html,最好用js改变表。
但如果不是......
添加到 HTML “colomn分隔符”类,如下所示:
<tr class="extra">
<td colspan="2" class="extrarow"><strong>Auth :: Permission</strong> </td>
</tr>
您的js
就像:
$(function () {
var columns = [];
$('tr.extra').each(function (i) {
var curr_col = $(this);
var next_col = $('tr.extra').eq(i+1);
var column = curr_col.nextUntil(next_col);
columns[i] = column;
});
columns.reverse();
var len = columns.length;
for (i = len-2; i >= 0; i--) {
columns[i].each( function (index, value){
var tds = $(this).children('td');
columns[len-1].eq(index).append(tds);
$(this).remove();
});
}
});
从这里开始 - jsfiddle