Html 表数据中没有重复图像 (td)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5815071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:17:23  来源:igfitidea点击:

No repeating image in a table data (td)

htmlhtml-email

提问by georgevich

Is it possible to stop repeating background image in a table data (TD) without CSS ?

是否可以在没有 CSS 的情况下停止在表格数据 (TD) 中重复背景图像?

For example

例如

<table>
  <tr>
     <td background="http://foobar.com/image.jpg">Some text</td>
  </tr>
</table>

I'm looking for a HTML solution, because I'm developing HTML template which will be used for a mail newsletter.

我正在寻找 HTML 解决方案,因为我正在开发将用于邮件通讯的HTML 模板。

采纳答案by Upvote

You can append the css to your tag straight in your html code:

您可以直接在 html 代码中将 css 附加到您的标签:

<td style="background-image:url(smile.gif); background-repeat:repeat;">

I think there is no way to do that just using html!

我认为仅使用 html 无法做到这一点!

回答by ebrandell

Simple answer: No.

简单的回答:不。

Fortunately, most emails you can use inline css styling. As such, I'd try the following and see if it accomplishes what you're looking for.

幸运的是,大多数电子邮件都可以使用内联 css 样式。因此,我会尝试以下操作,看看它是否能满足您的要求。

<td style="background:url(http://foobar.com/image.jpg) no-repeat;">Some text</td>

In the event that fails (as I've seen it do so before), you're only other option is place the image in an <img> tag and manipulate it so it falls underneath the text.

如果失败(正如我之前看到的那样),您唯一的选择是将图像放在 <img> 标签中并对其进行操作,使其位于文本下方。

See here for supported CSS attributes: http://www.campaignmonitor.com/css/

有关支持的 CSS 属性,请参见此处:http: //www.campaignmonitor.com/css/

Hope this helps.

希望这可以帮助。

回答by Dan Blows

For maximum compatibility, you should use both inline CSS and the HTML background attribute, as some clients ignore one but not the other.

为了获得最大的兼容性,您应该同时使用内联 CSS 和 HTML 背景属性,因为有些客户端会忽略一个而不是另一个。

<td style="background-image:url('http://www.example.com/smile.gif'); background-repeat:no-repeat;" background="http://www.example.com/smile.gif">Some text</td>

Some points to note:

需要注意的几点:

  1. You must use a absolute URL for the image src
  2. The quotes around the the URL in the background-image inline style should be there (the opposite of the normal CSS recommendation, but some clients have issues if the single quotes aren't included.)
  3. Don't use CSS shorthand, again some clients ignore it although they will parse the longhand. Also, some will set a background color of #000000 if you don't set a background-color in the shorthand version.
  4. Background images don't work at all in Outlook 2007, unless you use some rather nifty Microsoft proprietary code. Unfortunately, that code doesn't allow you to stop it repeating.
  1. 您必须为图像 src 使用绝对 URL
  2. 背景图像内联样式中 URL 周围的引号应该在那里(与正常的 CSS 建议相反,但如果不包含单引号,某些客户端会出现问题。)
  3. 不要使用 CSS 速记,同样一些客户会忽略它,尽管他们会解析速记。此外,如果您没有在速记版本中设置背景颜色,有些人会将背景颜色设置为 #000000。
  4. 背景图像在 Outlook 2007 中根本不起作用,除非您使用一些相当漂亮的 Microsoft 专有代码。不幸的是,该代码不允许您停止重复。

The best way to stop it repeating is simply to make the image much bigger than it needs to be, so that it never needs to repeat.

阻止它重复的最好方法就是让图像比它需要的大得多,这样它就不需要重复了。

回答by Samuel Larcher

background images are supported. Please check out this generator: http://backgrounds.cm

支持背景图片。请查看此生成器:http: //backgrounds.cm

If you want the image not to repeat just add an inline style:

如果您希望图像不重复,只需添加内联样式:

style="background-repeat: no-repeat;"

to the tags containing the background image.

到包含背景图像的标签。