Convert Horizontal <table> to vertical using CSS
-
Hi, I have a <table> like this:
Name Mike Watson
Title Accountant
Department Financeand I want to list it this way using CSS:
Name
Mike WatsonTitle
AccountantDepartment
FinanceHow can I do that please?
Technology News @ www.JassimRahma.com
-
Hi, I have a <table> like this:
Name Mike Watson
Title Accountant
Department Financeand I want to list it this way using CSS:
Name
Mike WatsonTitle
AccountantDepartment
FinanceHow can I do that please?
Technology News @ www.JassimRahma.com
<style>
table {
width: 100%
}
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
th,
td {
padding: 5px;
text-align: left;
}
</style<h2>Horizontal Headings:</h2>
<table>
<tr>
<th>Name</th>
<th>Telephone</th>
<th>Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table><h2>Vertical Headings:</h2>
<table>
<tr>
<th>Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 77 855</td>
</tr>
</table>
Sam
-
Hi, I have a <table> like this:
Name Mike Watson
Title Accountant
Department Financeand I want to list it this way using CSS:
Name
Mike WatsonTitle
AccountantDepartment
FinanceHow can I do that please?
Technology News @ www.JassimRahma.com
Hi Jassim, More than making a table it is better to make it more attractive. http://www.w3schools.com/css/css\_table.asp\[[^](http://www.w3schools.com/css/css_table.asp "New Window")]
-
Hi, I have a <table> like this:
Name Mike Watson
Title Accountant
Department Financeand I want to list it this way using CSS:
Name
Mike WatsonTitle
AccountantDepartment
FinanceHow can I do that please?
Technology News @ www.JassimRahma.com
Hi Jassim Rahma, You click the do it will send the result.
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$("a").click(function(){
$("table").each(function() {
var $this = $(this);
var newrows = [];
var i = 0;
$this.find("tr").each(function(){
$(this).find("td").each(function(){
i++;
if(newrows[i] === undefined) { newrows[i] = $(""); }
newrows[i].append($(this));
});
});
$this.find("tr").remove();
$.each(newrows, function(){
$this.append(this);
});
});return false;
});
});
</script>Name
Mike Watson
Title
Accountant
Department
Finance
</body>
</html>