DEMO
Css Solution: Simply turn your td
& th
to display:block;
& your tr
to display:table-cell;
CSS:
@media screen and (max-width:767px) {
table tr > *{
display: block;
}
table tr {
display: table-cell;
}
}
Drawback: If your cells have too much data the layout will break Example.
jQuery Solution: We can keep track of element height to stay the same DEMO
JS:
$(function () {
switchRowsAndCols("table", 767);
});
function switchRowsAndCols(thisTable, resolution) {
if ($(window).width() < resolution) {
switchRowsAndColsInnerFun(thisTable);
}
$(window).resize(function () {
if ($(window).width() < resolution) {
switchRowsAndColsInnerFun(thisTable);
}else{
switchRowsAndColsRemove(thisTable);
}
});
};
function switchRowsAndColsRemove(thisTable) {
$("tr > *", thisTable).css({
height: 'auto'
});
};
function switchRowsAndColsInnerFun(thisTable) {
var maxRow = $("tr:first-child() > *", thisTable).length;
for (var i = maxRow; i >= 0; i--) {
$("tr > *:nth-child(" + i + ")", thisTable).css({
height: 'auto'
});
var maxHeight = 0;
$("tr > *:nth-child(" + i + ")", thisTable).each(function () {
var h = $(this).height();
maxHeight = h > maxHeight ? h : maxHeight;
});
$("tr > *:nth-child(" + i + ")", thisTable).each(function () {
$(this).height(maxHeight);
});
};
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…