HTML Table element alignment - html

I am trying to figure out how to have a row of a table with two td tags stay on top of another row with only one td tag and align perfectly. I've tried colspan="2" on the bottom row but that doesn't work.
Here is what I have so far:
<table cellpadding="0" cellspacing="0" border="0" width="800"><!--wrapper-->
<table border="1">
<tr>
<td style="width: 50px"><img src="images/img1.jpg" />
</td>
<td><img src="images/img2.jpg" />
</td>
</tr>
<tr colspan="2">
<td><img src="images/img3.jpg" />
</td>
</tr>
</table>
</table>

Change
<tr colspan="2">
<td><img src="images/img3.jpg" />
</td>
to
<tr>
<td colspan="2"><img src="images/img3.jpg" />
</td>
The colspan should be on the td

colspan belongs on the <td> not the <tr>
<table cellpadding="0" cellspacing="0" border="0" width="800">
<!--wrapper-->
<table border="1">
<tr>
<td style="width: 50px">
<img src="images/img1.jpg" />
</td>
<td>
<img src="images/img2.jpg" />
</td>
</tr>
<tr>
<td colspan="2">
<img src="images/img3.jpg" />
</td>
</tr>
</table>
</table>
jsFiddle example

Related

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>

Collapsing table cells in media query for emailing

I had to create an emailing html and I can say it is definitely a hard thing to do. Now, making sure it is responsive is beyond obnoxious.
I'm stuck right now on a seemingly unsolvable problem.
Here is the problem : I have a table with 3 columns (column 1 is a table, column 2 a spacer colum, column 3 is a table).
When I go mobile, I want the third column to go under the column 1. But no matter what I try I cant do it.
Please note that the display parameter CANT be used. That's very important. Google mail doesnt know what display means (...)
The only thing that seem ok to use are : float and align.
Here is my jsfiddle
https://jsfiddle.net/cnw0o3wy/
the follow us and contact us cells are in the same table; that table must go under the first table. I fail to achieve that effect for now
<tr>
<td>
<table align="center">
<tr>
<td class="align-top grey responsive">
<table border="0" cellpadding="0" cellspacing="0" width="307">
<tbody>
<tr class="grey">
<td class="align-top"colspan="3"><img alt="" src="images/mobile.png" /></td>
</tr>
<tr class="grey">
<td width="113" class="w113"> </td>
<td>
<img src="images/appstore.png" title="Apple Store" />
</td>
<td>
<img src="images/googleplay.png" title="Google Play" />
</td>
</tr>
</tbody>
</table>
</td>
<td width="4"class="responsive">
</td>
<td class="responsive">
<table border="0" cellpadding="0" cellspacing="0" width="307" class="w307">
<tbody class="grey">
<tr class="grey">
<td class="align-top grey">
<table cellpadding="0" cellspacing="0" width="151" class="w151">
<tbody class="grey">
<tr>
<td style="line-height:6px;" height="6" width="151" class="w151"> </td>
</tr>
<tr>
<td style="padding-left: 7px;" class="t-gris px12 bold align-top">Follow us !</td>
</tr>
<!-- 32 PX SPACING -->
<tr>
<td height="36" width="151" class="w151"><img src="images/shim.png" alt="" height="31" /> </td>
</tr>
<tr class="align-center">
<td>
<img class="social" src="images/fb.png" alt="Facebook" />
<img class="social" src="images/twitter.png" alt="Twitter" />
<img class="social" src="images/mail.png" alt="Mail" />
</td>
</tr>
</tbody>
</table>
</td>
<td class="white">
<img alt="" src="images/shim.png" width="4" />
</td>
<td class="align-top grey">
<table cellpadding="0" cellspacing="0" width="151" class="w151">
<tbody class="grey">
<tr>
<td style="line-height:6px;" height="6" width="151" class="w151"> </td>
</tr>
<tr>
<td style="padding-left: 7px;" class="px12 bold t-gris align-top">Contact us !</td>
</tr>
<tr>
<td><img alt="" src="images/logo2.png" /></td>
</tr>
<tr>
<td style="padding-left: 7px;" class="px10 t-gris bold">
50/54 <br/>92100 <br/>+33 1 49 00 00 00 www.mail.fr
<span style="text-decoration: underline;">
courrier#mail.fr
</span>
</td>
</tr>
<tr>
<td style="line-height:7px;"height="7" width="151" class="w151"> </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</td>
</tr>
solved my problem with the following lines :
td[class="responsive-grey"],
td[class="responsive-grey responsive-grey-spacing"],
td[class="align-top grey responsive-grey"] {
float: left; width:100%;
}
basically float left on all three columns

why the second row td is the same width with the first one

<table width="980" border="0">
<tbody>
<tr>
<td width="25%">
<img width="300" style="overflow: hidden;" alt="" src="1.jpg">
</td>
<td width="75%">
<h1>ttt</h1>
<p>dgggg</p>
</td>
</tr>
<tr>
<td width="25%"><img alt="" src="98.jpg"></td>
<td width="25%"><img alt="" src="57_998.jpg"></td>
<td width="25%"><img alt="" src="7_998.jpg"></td>
<td width="25%"><img alt="" src="98.jpg"></td>
</tr>
</tbody>
</table>
Why is the second row td the same width with the first one(the first row td). the width="25%" doesn't work. how to correct it?
use colspan attribute to achieve this
<table width="980" border="0">
<tbody>
<tr>
<td width="25%"><h1>A</h1></td>
<td width="75%" colspan="3"><h1>B</h1></td>
</tr>
<tr>
<td width="25%">1</td>
<td width="25%">2</td>
<td width="25%">3</td>
<td width="25%">4</td>
</tr>
</tbody>
</table>
A good intro on the colspan attribute can be found here: http://reference.sitepoint.com/html/td/colspan
Here's a quick example similar to what you tried to achieve
http://jsbin.com/egahey/1/
by default in html, the column in a row takes the inherited width of the column in the preceding row ,
for achieving desired you have to use col span.
<table width="980" border="0">
<tbody>
<tr>
<td width="25%"><img width="300" src="1.jpg"></td>
<td width="75%" colspan="3"><h1>ttt</h1><p>dgggg</p></td>
</tr>
<tr>
<td width="25%"><img alt="" src="98.jpg"></td>
<td width="25%"><img alt="" src="57_998.jpg"></td>
<td width="25%"><img alt="" src="7_998.jpg"></td>
<td width="25%"><img alt="" src="98.jpg"></td>
</tr>
</tbody>
</table>
Imagine a table as an excel worksheet. All the rows in the same column must be the same width (of course, you can combine them just like excel too).
As for your question, you need to split the table into 2 tables to achieve different width:
<table width="980" border="0">
<tbody>
<tr>
<td width="25%"><img width="300" style="overflow: hidden;" alt="" src="1.jpg"></td>
<td width="75%"><h1>ttt</h1><p>dgggg</p></td>
</tr>
</tbody>
</table>
<table width="980" border="0">
<tbody>
<tr>
<td width="25%"><img alt="" src="98.jpg"></td>
<td width="25%"><img alt="" src="57_998.jpg"></td>
<td width="25%"><img alt="" src="7_998.jpg"></td>
<td width="25%"><img alt="" src="98.jpg"></td>
</tr>
</tbody>
</table>

Canvas inside table

I have a markup:
<table cellpadding="0" cellspacing="0" class="table_report_line">
<tbody>
<tr>
<td>
<div class="dvlefttable">
</div>
</td>
<td class="dvtoptable" colspan="4" width="100%">
Test
</td>
<td>
<div class="dvrighttable">
</div>
</td>
</tr>
<tr>
<canvas id="chartId" width="400" height="400" style="margin: 30px;">
</canvas>
</tr>
<tr>
<td>
</td>
<td colspan="4">
<br style="line-height: 15px;" />
</td>
<td>
</td>
</tr>
<tr>
<td colspan="6" class="bg_bottom_table">
</td>
</tr>
</tbody>
</table>
but when Firefox renders the page I see that it put canvas outside the table
<canvas id="chartId" style="margin: 30px;" height="400" width="400"> </canvas>
<table cellspacing="0" cellpadding="0" class="table_report_line">
<tbody>
<tr>
<td class="">
<div class="dvlefttable">
</div>
</td>
<td width="100%" colspan="4" class="dvtoptable">
Test
</td>
<td class="">
<div class="dvrighttable">
</div>
</td>
</tr>
<tr>
</tr>
<tr style="background: none repeat scroll 0% 0% transparent;">
<td class="td_border_left">
</td>
<td colspan="4" class="td_padding_left">
<br style="line-height: 15px;">
</td>
<td class="td_border_right">
</td>
</tr>
<tr>
<td class="bg_bottom_table" colspan="6">
</td>
</tr>
</tbody>
</table>
Why does it happen and how it possible to fix that?
You have to put the CANVAS inside of a TD element.
Change:
<tr>
<canvas id="chartId" width="400" height="400" style="margin: 30px;"></canvas>
</tr>
to:
<tr>
<td><canvas id="chartId" width="400" height="400" style="margin: 30px;"></canvas></td>
</tr>
General rule of thumb in cases like this is to use the HTML validator to see what you did wrong.

Rounded corners table HTML being cut on data increase

I have a HTML table with each td having a rounded corner image i put the images together and manage to get table with rounded corners .
Here's how it looks,
Here's the HTML for the below along with the css
<table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" frame="void"
style="width: 100%;">
<tr>
<td width="1%">
<img alt="" src="Images/frame_top_left.jpg" />
</td>
<td class="top_frame">
</td>
<td width="1%" align="right">
<img alt="" src="Images/frame_top_right.jpg" />
</td>
</tr>
<tr>
<td>
<img alt="" src="Images/frame_bottom_left.jpg" />
</td>
<td class="bottom_frame">
</td>
<td align="right">
<img alt="" src="Images/frame_bottom_right.jpg" />
</td>
</tr>
</table>
And heres the css
Now data is placed dynamically in the td with the css class "bottom_frame" whenever there's data placed the whole table gets changed heres how it looks when data is placed
heres the image of the HTML data inserted.
How do i let my table be maintained with any loss to it ????
Thanks & Regards,
Francis P.
You'd better add one more row to your table to put a content in it. Something like this:
<table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" frame="void"
style="width: 100%;">
<tr>
<td width="1%">
<img alt="" src="Images/frame_top_left.jpg" />
</td>
<td class="top_frame">
</td>
<td width="1%" align="right">
<img alt="" src="Images/frame_top_right.jpg" />
</td>
</tr>
<tr>
<td colspan="3" class="middle_frame">
-- Put your content right here --
</td>
</tr>
<tr>
<td>
<img alt="" src="Images/frame_bottom_left.jpg" />
</td>
<td class="bottom_frame">
</td>
<td align="right">
<img alt="" src="Images/frame_bottom_right.jpg" />
</td>
</tr>
</table>