Reputation:
I am trying to align the text in my table. It currently looks like this:
I would like to align the tile (in bold) in the center. Also, I am trying to get the values on the right, moved to the left.
Currently I have:
Javascript:
var table = $('<table/>',
{
id: 'table',
"class":'tables'
});
// ************************ Row 1 ************************************
row1 = $('<tr></tr>');
var head = $('<th></th>').addClass('dealHead').text(value.dealTitle);
row1.append(head);
table.append(row1);
// ********************************************************************
// ************************ Row 2 ************************************
row2 = $('<tr></tr>');
var col1 = $('<td></td>').addClass('name').text("Name: ");
var col2 = $('<td></td>').addClass('nameValue').text(value.name);
row2.append(col1);
row2.append(col2);
table.append(row2);
// ********************************************************************
// ************************ Row 3 ************************************
row3 = $('<tr></tr>');
col1 = $('<td></td>').addClass('address').text("Address: ");
col2 = $('<td></td>').addClass('addressValue').text(value.address);
row3.append(col1);
row3.append(col2);
table.append(row3);
// ********************************************************************
table.appendTo('body')
CSS:
body
{
background-color:#5CD65C;
}
.dealHead
{
text-align:center;
}
.name
{
border-top:thick double #0F0F00;
border-left:thick double #0F0F00;
border-bottom:thick double #0F0F00;
}
.nameValue
{
border-top:thick double #0F0F00;
border-right:thick double #0F0F00;
border-bottom:thick double #0F0F00;
text-align:left;
}
.address
{
border-top:thick double #0F0F00;
border-left:thick double #0F0F00;
border-bottom:thick double #0F0F00;
}
.addressValue
{
border-top:thick double #0F0F00;
border-right:thick double #0F0F00;
border-bottom:thick double #0F0F00;
text-align:left;
}
.tables
{
width="400";
border-collapse: collapse;
}
HTML
Pretty much an empty <body>
Would anyone know what I am doing wrong here?
Upvotes: 0
Views: 1302
Reputation: 6908
.tables { width="400"; ...
should be
.tables { width: 400px; ...
In order to have both cells the same with:
.tables td { width: 50%; }
var head = $('<th></th>').addClass('dealHead').text(value.dealTitle);
This is only one cell, make it like two:
var head = $('<th colspan="2"></th>').addClass('dealHead').text(value.dealTitle);
Upvotes: 0
Reputation: 1701
if this is plain html, I could have made the header <th>
to be of colspan=2
.
similarly make your header
var head = $('<th colspan="2"></th>').addClass('dealHead').text(value.dealTitle);
hope this would help.
Upvotes: 0
Reputation: 20408
In order to center the header you add colspan=2 that works,align the td's you have a class so add text-align-left like this
row1 = $('<tr></tr>');
var head = $('<th colspan="2"></th>').addClass('dealHead').text(value.dealTitle);
CSS
.test td {
text-align: right;
}
Example HTML
<table class="test">
<tr>
<th colspan="2">Title</th>
</tr>
<tr>
<td>data1</td>
<td>data2</td>
</tr>
</table>
Upvotes: 1