Is
<table border="0" cellspacing="0" cellpadding="0" align="center">
The same as
<table align="center">
?
As far as HTML only is considered, border="0" is the same as not using the border attribute at all. (Note that border=“0” with “curly” quotes, as in the heading of the question, is invalid in HTML; the quotes, if used, must be "straight" or 'single-straight'.) But in the presence of CSS, it may make a difference; the explicit attribute border="0" may override CSS settings.
Regarding cellspacing and cellpadding, mentioned in the body of the question, they do make a difference. Their default values, by implementations (the specs are silent about this), are small positive integers, typically 2.
The border will be the same but unless you add the cell padding and cell spacing as zero you'll get around 2px of each on your cells.
You could set this to zero in your style sheet though and leave them black. But the default behavior will add the padding/spacing in.
Related
I am hoping someone can help me out here.
MANY months ago, I came on here looking for an answer to why my email wasn't displaying at 600px on a certain email client(I can't remember which one but it's probably Gmail). I have been using the following code over the last few months:
<table align="center" bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0"
style="margin: auto;" width="600px;" width="600">
<tr>
<td style="width:600px;" >
For the life of me, I cannot remember why the width is defined in both px and without px on the table. Then defined again on the TD in 600px. I've Googled it like crazy but no answers so far. Any help would be appreciated.
Setting the width of a table
In a nut-shell, there are two ways to set a width for table or its inner elements (e.g. tr, td, etc—which support width)
Using width property: as part of HTML spec, you can use width property as part of the markup. Like you have width="600" in your table tag. Please note, however, only numeric pixel value or percentage is valid (https://www.w3.org/TR/html401/struct/tables.html#adef-width-TABLE )
Using inline style property or CSS declaration: Like how you have style: 600px; in your td. Here, any valid CSS units can be used.
While it's typically considered a bad practice to use HTML markup for styling or/and rely heavily on inline styling, for HTML emails not only rely on both—often used simultaneously. Because, well, HTML emails are its own kind of beast.
Why table width doesn't render as intended
It's hard to answer with specific context. Table cells could collapse when there's no content inside, which might affect the widths of their containing elements. There might have been a typo. There might have been an invalid value used in a style declaration. There might have been a conflicting style definition. Or any number of other factors.
The only needed way to set a width on a <table> for an HTML email is to use an inline style.
<table style="width:600px; margin:auto; background-color:#fff;" align="center" border="0" cellpadding="0" cellspacing="0" >
This is the best way to do it because it will take into account The Outlooks on Windows at 120dpi rendering. This is also a personal recommandation of mine to prefer styles over attributes, which is why I moved the background-color in a style as well above.
The only exception to this is for images. The Outlooks on Windows don’t understand a width style on images, only a width attribute. So you always need to define a fixed width for Outlook on Windows in an HTML attribute, and then a fluid width in a style for other clients if you need it.
<!-- Bad example -->
<img src="example.jpg" alt="" width="100%" />
<!-- Good example -->
<img src="example.jpg" alt="" width="600" style="width:100%;" />
use 1 - 100 % at the place of px
I am looking for a HTML attribute (not a CSS declaration) which will remove the padding from the <table> element. I would also like to achieve the same thing as is done with border-collapse: collapse;
I know that this can be very easily done with CSS by setting the margin and border-collapse properties of the table.
In my specific case, I am generating final documents with an old program which cannot read CSS.
Are you looking for the classic attributes:
<table cellpadding="0" cellspacing="0" border="0">
that can control the cell padding, spacing and border?
Okay, I have an exam on friday on html basics, the only problem I still have is that the hspace and vspace attribute in combination with an iframe, it just does not give me space between the iframe and the tekst next to it... if it try it with an image it works super. I will give an example.
<img src="image.jpg" align="left" hspace="10"> gives me 10 pixels of space
<iframe src="something.html" align="left" hspace="10"> gives me an ifram to the left to a text (what is what I want) but it does not give me the 10 px of whitespace
we are nonly alowed to use html in this test. Can somebody please help me? Thanks!
The iframe element never had hspace and vspace attributes, or anything like that, in any specification or implementation.
If you need to do things with HTML alone, no CSS allowed, presumably as an odd exercise, then you need to resort to rather ugly tricks. To set spacing on all sides of an iframe element, you could use a single-cell table with cell padding set:
<table cellpadding="10" align="left"><tr>
<td><iframe src="about:blank"></iframe>
</table>
Hello world!
But if you need spacing e.g. only to the right of the iframe element, you can use a different table trick, with a 10px wide cell between it and the text. Note that this affects the overall layout, since now you have the stuff in a table.
<table cellpadding="0" cellspacing="0">
<tr valign="top">
<td><iframe src="about:blank"></iframe></td>
<td width="10"></td>
<td>Hello world!</td>
</table>
In normal HTML for browsers, making elements overlap is easy.
But in the dark world of HTML email, where the motto is "code like it's 1996" because Outlook uses the rendering engine from MS Word and Gmail removes almost everything, every method for making two elements overlap that I can think of is unsuitable due to poor client support:
Position isn't supported in many clients, so no position: absolute; or position: relative; and no top, left, right...
Negative margins get removed by Gmail and others. So, no negative margins.
Using the 'overhang' from an element with overflow: visible; and a width and height that is less than the size of the element's contents doesn't work very well when <img> tags all need explicit heights and widths or where layouts, due to lack of float support and erratic treatment of <div>s, by necessity need to be based on tables most of the time. (that said, if anything is possible, something based on this seems like the most likely option)
Nothing involving background images is an option as these are removed in Gmail and others
Don't even think of trying to use CSS3 or javascript in a HTML email...
Is there anything that can be reliably used to create overlap between elements in cross-client HTML emails? And/or any way to make an element extend out from its bounding box without affecting the positioning of its neighbours?
For example, suppose you wanted to do something like this (dashed lines and backgrounds showing bounding boxes), where the large image hangs down over the row below rather than pushing it down...
An element (in this case, an <img>, but not necessarily an image) overlaps other elements (in this case, the row below - but not necessarily a separate row) without pushing them away.
Is there any way to do that without major client compatibility problems?
EDIT: Just found this piece of crazy twisted genius: making table cells overlap using colspans and rowspans. This could be an option, not yet thoroughly tested its cross-client rendering though, any info from prior experience or research is welcome.
Assume we're making a newsletter where we can't predict what clients our customers will be using, so we have to support popular mainstream email clients: Outlook, Gmail, Yahoo, Hotmail, Thunderbird, iOS/OSX, Android...
A little late to the conversation, but this similar answer is the technique you are looking for.
Your example is a lot more complex however as you are spanning over both rows and columns. I'm up for the challenge:
<table width="600" border="0" cellpadding="0" cellspacing="0">
<tr><!-- This row is needed to enforce col widths in Outlook -->
<td width="100">
</td>
<td width="300">
</td>
<td width="200">
</td>
</tr>
<tr>
<td width="400" valign="top" height="80" colspan="2" bgcolor="#bbbbbb">
Title Here
</td>
<td width="200" valign="top" height="120" rowspan="2" bgcolor="#dddddd">
Image Here
</td>
</tr>
<tr>
<td width="100" valign="top" height="540" rowspan="2" bgcolor="#cccccc">
Column<br>...<br>...<br>...
</td>
<td width="300" valign="top" height="40" bgcolor="#aaaaaa">
Heading 1
</td>
</tr>
<tr>
<td width="500" valign="top" height="500" colspan="2" bgcolor="#eeeeee">
Content<br>...<br>...<br>...
</td>
</tr>
</table>
This is as close as you'll get. You can't make non-rectangles, so the top Header in the body has to be in it's own cell.
The genius' solution worked in most situation. But for outlook 2007, 2010 and 2013, it didn't work for the rowspan will be deleted.
I've been tasked with creating a clean template for our HTML newsletter with circulates to about 70k subscribers. As expected, they're hoping for it to be as consistent across as many e-mail clients as possible, so I'm following widely suggested HTML e-mail practice and using nested tables and in-line style.
I'm trying to set a bgcolor to each <td> that displays an image - the reason being that if someone has the images on their e-mail client turned off, they'll still be able to see the shape of the table cells (and their experience will still be somewhat visual), but I'm having difficulty keeping the bgcolor within the cell, it seems to bleed into the space between cells. Here's an example:
<tr>
<td width="200" height="200" bgcolor="#CCCCCC">
<img src="image.png" height="200" width="200" alt="Image!">
</td>
</tr>
From this code, instead of the background being invisible under the image when the image is visible because they're both 200x200, I see about 10px of the grey pushing down into the bottom and right side of the image and intruding into the white space around the cells. What is going on and how can I fix this?
EDIT: Here's an image of what it's doing:
Have you set the css style of the table to border-collapse? Like so:
<table style="border-collapse: collapse;">
If that has no effect, and there is no margin on the images, have you tried setting padding to 0?
Have you set the cellpadding and cellspacing properties on the table tag?
http://www.w3schools.com/tags/att_table_cellspacing.asp