首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何编写继承外部css (html-email)的css?

如何编写继承外部css (html-email)的css?
EN

Stack Overflow用户
提问于 2015-12-16 21:29:41
回答 2查看 59关注 0票数 0

我需要写一封html电子邮件。一切看起来都很正常,但是代码看起来很乱。

我有以下html表:

代码语言:javascript
复制
<table bgcolor="#ffffff" align="center" border="0" cellpadding="0" cellspacing="0" style="width:600px;border: 1px solid #cccccc" class="responsive-table100">

请关注“responsive table100”类。这个类不是我写的,它来自一个我不知道的地方。我只知道用这个类,我可以做一个响应表。它似乎来自媒体css。

代码语言:javascript
复制
@media screen and (max-width:700px) {
        table[class="responsive-table100"] {
            width: 100% !important;
        }
    }

    @media screen and (max-width:500px) {
        *[class="mobile-width-20"] {
            width: 20px !important;
        }
    }

我试着让代码更简短,如下所示:

代码语言:javascript
复制
.container-table {
        border: 0;
        border-collapse: collapse;
        background-color: #ffffff;
        width:600px;
        border: 1px solid #cccccc;
        text-align: center;
        margin:0px auto;
    }

<table class="container-table responsive-table100">

在上面的代码中,只应用了.container-table css,而没有应用responsive table100。我怎么才能修复它?

谢谢

EN

回答 2

Stack Overflow用户

发布于 2015-12-16 21:50:38

这不是一个答案,而是一个指南。为了更好地开发css ..

如果您要获取HTML5文档(这是绝对推荐的)。不支持使用像bgcolor这样的属性。

现在最基本的是:

代码语言:javascript
复制
.iCALLyou {
  /* this is only for elements with class iCallyou*/
  background-color: red;
}
.YOUcallMe {
  /* this is only for elements with class YOUcallMe*/
  color: green;
}
/* if you give an element a class or more (you seprate with <space>) he will look for CSS code that targets the class  */
代码语言:javascript
复制
<table class="iCALLyou YOUcallMe">

  <tr>
    <td>RUNNNN</td>
  </tr>

</table>


<table class="YOUcallMe">

  <tr>
    <td>RUNNNN NOW</td>
  </tr>

</table>


<table class="iCALLyou">

  <tr>
    <td>RUNNNN FAR AWAY</td>
  </tr>

</table>

所以如果你使用前面的例子并稍微修改一下:

代码语言:javascript
复制
.iCALLyou {
  /* this is only for elements with class iCallyou*/
  background-color: red;
}
.YOUcallMe {
  /* this is only for elements with class YOUcallMe*/
  color: green;
}
/* if you give an element a class or more (you seprate with <space>) he will look for CSS code that targets the class  */

.borderLittle {
  border: 1px solid black;
}
.borderFat {
  border: 9px solid blue;
}
代码语言:javascript
复制
<table class="iCALLyou YOUcallMe">

  <tr>
    <td>RUNNNN</td>
  </tr>

</table>


<table class="YOUcallMe">

  <tr>
    <td>RUNNNN NOW</td>
  </tr>

</table>


<table class="iCALLyou borderLittle borderFat">

  <tr>
    <td>RUNNNN FAR AWAY (the classes with border that is last defined will be shown)</td>
  </tr>

</table>

因此,要在元素中包含responsive 100类,您需要在css- So表中定义它。

但是..。在邮件中,内联样式是更好的<element style="background-color: pink"></element>

票数 1
EN

Stack Overflow用户

发布于 2015-12-17 05:38:22

答案是:您的属性选择器在CSS中不太正确。

代码语言:javascript
复制
table[class="responsive-table100"]

这将匹配一个类等于“responsive table100”的表。(仅此而已。)

代码语言:javascript
复制
table[class~="responsive-table100"]

这(使用~= )将匹配一个表,其中类包含“-table100”。一般来说,在编写电子邮件程序时,我会在几乎所有的属性选择器中使用~=。

的好处:如果你想让它在Gmail中工作,可以使用摘要属性,而不是类名的属性,因为Gmail从你的代码中去掉了类和IDs。

CSS:

代码语言:javascript
复制
table[summary~="responsive-table100"]

HTML:

代码语言:javascript
复制
<table summary="responsive-table100">
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34313367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档