Html 使用 style="color:#fff" 为表格行着色以显示在电子邮件中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10245724/
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-28 23:54:50  来源:igfitidea点击:

Color a table row with style="color:#fff" for displaying in an email

htmlcsshtml-tablehtml-email

提问by naveen

We would like to display order details as table in an email

我们想在电子邮件中以表格形式显示订单详细信息

?<table>
    <thead>
        <tr>
            <th>Header 1</th>
            <th>Header 2</th>
            <th>Header 3</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>blah blah</td>
            <td>blah blah</td>
            <td>blah blah</td>
        </tr>
    </tbody>
</table>???????????????????????????????????????????

We would ideally want the header to have background-color as '#5D7B9D' and text-color as '#fff'.
We are using bgcolor='#5D7B9D'for changing the background-color and are unable to find an alternative to do the same for changing the text-color.
As most of the email providers strip the CSS, we cannot use styleattribute at all.

理想情况下,我们希望标题的背景颜色为“#5D7B9D”,文本颜色为“#fff”。
我们正在bgcolor='#5D7B9D'用于更改背景颜色,但无法找到替代方法来更改文本颜色。
由于大多数电子邮件提供商剥离了 CSS,我们根本无法使用style属性。

The questions are

问题是

  1. How to make the header text appear in white?
  2. Are there any alternate methods?
  1. 如何使标题文本显示为白色?
  2. 有没有其他替代方法?

回答by RynoRn

For email templates, inline CSS is the properly used method to style:

对于电子邮件模板,内联 CSS 是正确使用样式的方法:

<thead>
    <tr style="color: #fff; background: black;">
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
    </tr>
</thead>

回答by Shailender Arora

you can easily do like this:-

你可以很容易地这样做:-

    <table>
    <thead>
        <tr>
          <th bgcolor="#5D7B9D"><font color="#fff">Header 1</font></th>
          <th bgcolor="#5D7B9D"><font color="#fff">Header 2</font></th>
           <th bgcolor="#5D7B9D"><font color="#fff">Header 3</font></th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>blah blah</td>
            <td>blah blah</td>
            <td>blah blah</td>
        </tr>
    </tbody>
</table>

Demo:- http://jsfiddle.net/VWdxj/7/

演示:- http://jsfiddle.net/VWdxj/7/

回答by WolvDev

Try to use the <font>tag

尝试使用<font>标签

?<table> 
    <thead> 
        <tr> 
            <th><font color="#FFF">Header 1</font></th> 
            <th><font color="#FFF">Header 1</font></th> 
            <th><font color="#FFF">Header 1</font></th> 
        </tr> 
    </thead> 
    <tbody> 
        <tr> 
            <td>blah blah</td> 
            <td>blah blah</td> 
            <td>blah blah</td> 
        </tr> 
    </tbody> 
</table>

But I think this should work, too:

但我认为这也应该有效:

?<table> 
    <thead> 
        <tr> 
            <th color="#FFF">Header 1</th> 
            <th color="#FFF">Header 1</th> 
            <th color="#FFF">Header 1</th> 
        </tr> 
    </thead> 
    <tbody> 
        <tr> 
            <td>blah blah</td> 
            <td>blah blah</td> 
            <td>blah blah</td> 
        </tr> 
    </tbody> 
</table>

EDIT:

编辑:

Crossbrowser solution:

跨浏览器解决方案:

use capitals in HEX-color.

使用十六进制颜色的大写字母。

<th bgcolor="#5D7B9D" color="#FFFFFF"><font color="#FFFFFF">Header 1</font></th>

回答by Reid Svntn

Rather than using direct tags, you can edit the css attribute for the color so that any tables you make will have the same color header text.

您可以编辑颜色的 css 属性,而不是使用直接标记,这样您制作的任何表格都将具有相同颜色的标题文本。

thead {
    color: #FFFFFF;
}