Inner table content not aligned with outer table - html

I am creating a table inside another table. I have divided the columns to be the exact same ratio as the outer table. However, the columns are not aligned with outer table columns. Can anyone tell me what I am missing?
<html>
<div style="overflow:scroll;height:140px;width:100%;overflow:auto" style="background-color:black">
<table width="100%" style="padding:0; margin:0;" cellpadding="0">
<tr class="tbl_header" cellpadding="0">
<td width="3%">test1</td>
<td width="7%">test2</td>
<td width="3%">test3</td>
<td width="12%">test4</td>
<td width="7%">test5</td>
<td width="10%"test6</td>
<td width="7%">test7</td>
</tr>
<tr style="background-color:yellow">
<td colspan="7" style="background-color:yellow">
<div style="overflow:scroll;height:110px;width:100%;overflow:auto;border:none;background-color:green">
<table width="100%" style="border:none;background-color:red" cellpadding="0">
<tr class="even">
<td width="3%">2</td>
<td width="7%" class="tdAlign">Testing </td>
<td width="3%" class="tdAlign">Testing </td>
<td width="12%" class="tdAlign">Testing Testing Testing</td>
<td width="7%">Testing_1</td>
<td width="10%">Testing_2</td>
<td width="7%">Testing_3</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</html>

When I inspect the table with chromes web kit. I see that the tables with 3% then they are supposed to be, because of the text length. U can fix this by adding table-layout: fixed to both your <table> elements.
If U want to use a table header I suggest using <th> (see here)

<html>
<div style="overflow:scroll;height:140px;width:100%;overflow:auto" style="background-color:black">
<table width="100%" style="padding:0; margin:0;" cellpadding="0">
<tr class="tbl_header" cellpadding="0">
<td width="3%">test1</td>
<td width="7%">test2</td>
<td width="3%">test3</td>
<td width="12%">test4</td>
<td width="7%">test5</td>
<td width="10%">test6</td>
<td width="7%">test7</td>
</tr>
<tr style="background-color:yellow">
<td colspan="7" style="background-color:yellow">
<div style="overflow:scroll;height:110px;width:100%;overflow:auto;border:none;background-color:green">
<table width="100%" style="border:none;background-color:red" cellpadding="0">
<tr class="even">
<td width="3%">2</td>
<td width="7%" class="tdAlign">Testing </td>
<td width="3%" class="tdAlign">Testing </td>
<td width="12%" class="tdAlign">Testing Testing Testing</td>
<td width="7%">Testing_1</td>
<td width="10%">Testing_2</td>
<td width="7%">Testing_3</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</html>
Looks like you missed a closing tag for a <TD>(<td width="10%">test6</td>). Hope this helps. Let me know

Related

How to align two TD with different length in same row<tr>

Please help me how to align this structure properly. I would like to decrease the size of td "Todays Special" to considerable height. This td grows based on my value say if new fruits added then the header td also grows.
Be kind to help me to resolve this
<table>
<tr>
<td class="title">Todays Special</td>
<td>
<div style="height: 120px; width:100%;overflow-y:auto;">
<table style="height: auto; width:100%;" valign="top">
<tbody>
<tr style="vertical-align: baseline;">
<td colspan="4" class="title">6</td>
<td colspan="4" class="title">mango</td>
</tr>
<tr style="vertical-align: baseline;">
<td colspan="4" class="title">23</td>
<td colspan="4" class="title">orange</td>
</tr>
<tr style="vertical-align: baseline;">
<td colspan="4" class="title">29</td>
<td colspan="4" class="title">banana</td>
</tr>
<tr style="vertical-align: baseline;">
<td colspan="4" class="title">47</td>
<td colspan="4" class="title">papaya</td>
</tr>
<tr style="vertical-align: baseline;">
<td colspan="4" class="title">11959</td>
<td colspan="4" class="title">kiwi</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</table>
If you edit the "Todays Special" td, you can set the desired width and font-size through the style property of the td tag. And also set the alignment you want.
As you are not making a Table header from a row, you have to set different styles to the main td and the rest of the table.
Hope I helped.
Assuming you just want to match the height of the column Todays's Special. You can do this by adding the rowspan according to the no. of items in the list
<td class="title" rowspan="5">Todays Special</td>
<div>
<table style="height: auto;" valign="middle">
<tbody>
<tr>
<td class="title" rowspan="5">Todays Special</td>
<td class="title">6</td>
<td class="title">mango</td>
</tr>
<tr>
<td class="title">23</td>
<td class="title">orange</td>
</tr>
<tr>
<td class="title">29</td>
<td class="title">banana</td>
</tr>
<tr>
<td class="title">47</td>
<td class="title">papaya</td>
</tr>
<tr>
<td class="title">11959</td>
<td >kiwi</td>
</tr>
</tbody>
</table>
</div>

Filling an automatic-width table cell with a fixed-layout table

This sounds very similar to previous questions, but I've not found something that matches what I'm trying to do here.
My current code (very verbose with everything in line) looks like this:
td { border: 1px solid black }
<table style="table-layout:fixed">
<tr>
<td>
<table style="table-layout:fixed">
<tr>
<td style="background-color:red"></td>
<td style="background-color:limegreen;width:30px"></td>
<td style="background-color:blue"></td>
<tr>
</table>
</td>
<td>
<table style="table-layout:fixed">
<tr>
<td style="background-color:red"></td>
<td style="background-color:limegreen;width:30px"></td>
<td style="background-color:blue"></td>
<tr>
</table>
</td>
<td>
<table style="table-layout:fixed">
<tr>
<td style="background-color:red"></td>
<td style="background-color:limegreen;width:30px"></td>
<td style="background-color:blue"></td>
<tr>
</table>
</td>
<td>
<table style="table-layout:fixed">
<tr>
<td style="background-color:red"></td>
<td style="background-color:limegreen;width:30px"></td>
<td style="background-color:blue"></td>
<tr>
</table>
</td>
</tr>
<tr>
<td style="width:25%;text-align:center">Some text here</td>
<td style="width:25%;text-align:center">More text</td>
<td style="width:25%;text-align:center">Hi</td>
<td style="width:25%;text-align:center">Somewhat longer text</td>
</tr>
</table>
What I'm trying to accomplish should look like this:
That is, the four main columns should all be the same width, which is the width of the largest content of any of the columns.
The green columns should always be 30px, and the red and blue columns should fill the remaining space each side of that middle column, only up to the width available in the auto-sized outer column.
Setting the internal tables to 100% width makes this happen, but of course the outer table then takes up the entire page width.
I'm also aware that using tables for this is probably not a great idea now we can use CSS, but I'd like to get this example working in tables before 'translating' it.
I'm very opposed to using JavaScript to solve this, for the record!
Edit: I also tried putting all 'subcolumns' in one row, and setting the text to colspan three at a time, with the 25% then applied to that. This ended up confusing the engine, and the width ended up about 75% of the page.
<table style="table-layout:fixed" border="1">
<tr style="font-size: 1px;">
<td width="25%" colspan="3"> </td>
<td width="25%" colspan="3"> </td>
<td width="25%" colspan="3"> </td>
<td width="25%" colspan="3"> </td>
</tr>
<tr style="font-size: 6px;">
<td style="background-color:red"> </td>
<td style="background-color:green"><div style="width: 30px;"> </div></td>
<td style="background-color:blue"> </td>
<td style="background-color:red"> </td>
<td style="background-color:green"><div style="width: 30px;"> </div></td>
<td style="background-color:blue"> </td>
<td style="background-color:red"> </td>
<td style="background-color:green"><div style="width: 30px;"> </div></td>
<td style="background-color:blue"> </td>
<td style="background-color:red"> </td>
<td style="background-color:green"><div style="width: 30px;"> </div></td>
<td style="background-color:blue"> </td>
</tr>
<tr>
<td colspan="3" style="text-align:center">Some text here</td>
<td colspan="3" style="text-align:center">More text</td>
<td colspan="3" style="text-align:center">Hi</td>
<td colspan="3" style="text-align:center">Somewhat longer text</td>
</tr>
</table>
this might solve your answer, your previous code html elements are not properly closed look on that also.

Gap between <tr>

I am creating a table that has 2 rows, that has different colors. There appears to be a gap between the rows and I want to close the gap, how can I do that?
<table width="100%">
<tr>
<td bgcolor="grey">
<table width="50%" style="margin:auto;">
<tr>
<td bgcolor="white" align="center">
<img src="">Test
</td>
</tr>
<tr>
<td align="center" bgcolor="#99CB55">
<img width="50%" src="xxx">
</td>
</tr>
</table>
</td>
</tr>
</table>
I need to use the css <style> because I'm sending this via Email (PHPMailer) and all the text will only be in HTML (+CSS using )
You can try table {border-spacing: 0; }
table {border-spacing: 0; }`
<table width="100%">
<tr>
<td bgcolor="grey">
<table width="50%" style="margin:auto;">
<tr>
<td bgcolor="white" align="center">
<img src="">Test
</td>
</tr>
<tr>
<td align="center" bgcolor="#99CB55">
<img width="50%" src="xxx">
</td>
</tr>
</table>
</td>
</tr>
</table>

Aligning elements in table

I would like for top 4 elements to stretch across the top, and bottom two to also look like they belong to the same table, stretch and not be so squeezed. Can I accomplish this without adding empty <td>s?
This is how it looks like right now:
http://www.w3schools.com/code/tryit.asp?filename=F0OOEL3HH55Y
My code:
<table cellspacing="2" cellpadding="2" width="650" border="0">
<tr>
<td height="8" class="header" width="300">Weight Per Book (lb.)</td>
<td height="8" class="header" width="300">Cost per Book</td>
<td height="8" class="header" width="200">Quantity for whole order</td>
<td height="8" class="header" width="400">Capability Complexity Level For TO</td>
</tr>
<tr>
<td height="16">2.0</td>
<td height="16">0.00</td>
<td height="16">0</td>
<td height="16">4</td>
</tr>
<tr valign="bottom">
<td class="header">Distribute ID Order to Home Plant</td>
<td class="header">Distribute All OTR's to Home Plant</td>
</tr>
<tr>
<td>No</td>
<td>No</td>
</tr>
</table>
You can use the colspan attribute to do that. This attribute define the number of columns a particular cell should span.
Here is an example:
<table cellspacing="2" cellpadding="2" width="650" border="0">
<tr>
<th colspan="4">Production</th>
</tr>
<tr>
<td height="8" class="header" width="300">Weight Per Book (lb.)</td>
<td height="8" class="header" width="300">Cost per Book</td>
<td height="8" class="header" width="200">Quantity for whole order</td>
<td height="8" class="header" width="400">Capability Complexity Level For TO</td>
</tr>
<tr>
<td height="16">2.0</td>
<td height="16">0.00</td>
<td height="16">0</td>
<td height="16">4</td>
</tr>
<tr valign="bottom">
<td colspan="2" class="header">Distribute ID Order to Home Plant</td>
<td colspan="2" class="header">Distribute All OTR's to Home Plant</td>
</tr>
<tr>
<td colspan="2">No</td>
<td colspan="2">No</td>
</tr>
</table>
Hope this helps!

How do I get a table with 3 columns and the third colums only has 1<td> 100%

<html>
<body>
<table align="left" border="0" cellpadding="1" cellspacing="1" style="width: 1000px;">
<tbody>
<tr>
<td width="300">Hanrathsingel 14</td>
<td width="300">Home</td>
<td width="400" height="100%">This one has to take the full height of the table</td>
</tr>
<tr>
<td width="300">1252 AE Laren</td>
<td width="300">Wie zijn wij</td>
</tr>
<tr>
<td width="300">T. 035-6231419</td>
<td width="300">Informatie</td>
</tr>
<tr>
<td width="300">M. 06-21700357</td>
<td width="300">Algemene Voorwaarden</td>
</tr>
<tr>
<td width="300">laren#qualitysites4all.com</td>
<td width="300">Contact</td>
</tr>
</tbody>
</table>
</body>
</html>
How do I get the column to be 100% of the table height but the other columns must keep their height?
Because I want to put a widget in there but I have to work in my boss his cms and I am not allowed to make new divs :(
Try rowspan:
<table align="left" border="0" cellpadding="1" cellspacing="1" style="width: 1000px;">
<tbody>
<tr>
<td width="300">Hanrathsingel 14</td>
<td width="300">Home</td>
<td width="400" rowspan="5">This one has to take the full height of the table</td>
</tr>
<tr>
<td width="300">1252 AE Laren</td>
<td width="300">Wie zijn wij</td>
</tr>
<tr>
<td width="300">T. 035-6231419</td>
<td width="300">Informatie</td>
</tr>
<tr>
<td width="300">M. 06-21700357</td>
<td width="300">Algemene Voorwaarden</td>
</tr>
<tr>
<td width="300">laren#qualitysites4all.com</td>
<td width="300">Contact</td>
</tr>
</tbody>
</table>
Example
JSFiddle Example
Use rowspan="5" in that TD.
Rowspan attribute, tells your element to "get the height" of 5 rows in this case.
If you have dinamic content remember to update this value to the actual number of rows of your table.