Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何让媒体查询/css在html电子邮件中工作

如何让媒体查询/css在html电子邮件中工作
EN

Stack Overflow用户
提问于 2019-02-18 05:57:50
回答 1查看 263关注 0票数 0

我在获取正确显示的html电子邮件时遇到问题。html包含媒体查询,以使其响应不同大小的设备...它可以在浏览器中正确显示,但当作为电子邮件发送时,css似乎无法正常工作来调整图标位置。

我尝试过缩小css,让css变得重要,等等,但都没起作用。在检查Gmail中的电子邮件的html时,我注意到类名称已经被Google更改了,并且没有应用任何规则。不确定为什么会发生这种情况,或者如何绕过它。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <meta name=viewport content="width=device-width, initial-scale=1">
        <title>Testing Testing 123</title>
        <style type="text/css">
            #bodyBg {
                margin: 0px;
                padding: 0px;
                background-color: white;
            }


            @media only screen 
            and (max-device-width: 325px)
            and (min-device-height: 500px)
            and (max-device-height: 580px){
                .helpfulIcons {
                    height:62px; 
                    width: 66px;
                }
                #helpfulIconTable {
                    position: relative; 
                    bottom: 150px;
                    width:100%
                }
                #socialIconTable {
                    position: relative; 
                    bottom: 550px; 
                    width: 90%;
                    left: -8px;
                    margin-left:auto; 
                    margin-right:auto;                    
                }
                .socialIcons {
                    height: 79.36px; 
                    width: 84.48px; 
                }
                socialCells {
                    padding-right: 5px; 
                    width:25%; 
                    text-align: center;
                }
            }


            @media only screen 
            and (min-device-width: 326px)
            and (max-device-width: 364px) {
                .helpfulIcons {
                    height:62px; 
                    width: 66px;
                }
                #helpfulIconTable {
                    position: relative; 
                    bottom: 150px;
                    width:100%
                }
                #socialIconTable {
                    position: relative; 
                    bottom: 550px; 
                    width: 90%;
                    left: -8px;
                    margin-left:auto; 
                    margin-right:auto;                    
                }
                .socialIcons {
                    height: 79.36px; 
                    width: 84.48px; 
                }
                socialCells {
                    padding-right: 5px; 
                    width:25%; 
                    text-align: center;
                }
            }


            @media only screen 
            and (min-device-width: 365px)
            and (max-device-width: 499px)
            and (max-device-height: 700px){
                .helpfulIcons {
                    height:62px; 
                    width: 66px;
                }
                #helpfulIconTable {
                    position: relative; 
                    bottom: 150px; 
                    width:100%
                }
                #socialIconTable {
                    position: relative; 
                    bottom: 550px; 
                    width: 100%;
                    left: -8px;

                }
                .socialIcons {
                    height: 79.36px; 
                    width: 84.48px; 
                }
                socialCells {
                    padding-right: 5px; 
                    width:25%; 
                    text-align: center;
                }
            }


            @media only screen 
            and (min-device-width: 365px)
            and (max-device-width: 499px)
            and (min-device-height: 701px){
                .helpfulIcons {
                    height:124px; 
                    width: 132px;
                }
                #helpfulIconTable {
                    position: relative; 
                    bottom: 160px; 
                    width:100%
                }
                #socialIconTable {
                    position: relative; 
                    bottom: 850px; 
                    width: 100%;
                    left: -8px;

                }
                .socialIcons {
                    height:124px; 
                    width: 132px; 
                }
                socialCells {
                    padding-right: 5px; 
                    width:25%; 
                    text-align: center;
                }
            }

            @media only screen 
            and (min-device-width: 400px)
            and (max-device-width: 450px)
            and (min-device-height: 790px)
            and (max-device-height: 850px){
                .helpfulIcons {
                    height:248px; 
                    width: 264px;
                }
                #helpfulIconTable {
                    position: relative; 
                    bottom: 300px; 
                    width:100%
                }
                #socialIconTable {
                    position: relative; 
                    bottom: 1620px; 
                    width: 90%;
                    left: -8px;
                    margin-left:auto; 
                    margin-right:auto;                    
                }
                .socialIcons {
                    height: 248px; 
                    width: 264px; 
                }
                socialCells {
                    padding-right: 5px; 
                    width:25%; 
                    text-align: center;
                }
            }



            @media only screen 
            and (min-device-width: 400px)
            and (max-device-width: 450px)
            and (min-device-height: 700px)
            and (max-device-height: 780px){                
                .helpfulIcons {
                    height: 75.39px; 
                    width: 80.256px; 
                }
                #helpfulIconTable {
                    position: relative; 
                    bottom: 165px; 
                    width:100%                }
                #socialIconTable {
                    position: relative; 
                    bottom: 590px; 
                    width: 90%;
                    left: -8px;
                    margin-left:auto; 
                    margin-right:auto;                    
                }
                .socialIcons {
                    height: 79.36px; 
                    width: 84.48px; 
                }
                socialCells {
                    padding-right: 5px; 
                    width:25%; 
                    text-align: center;
                }
            }



            @media only screen 
            and (min-device-width: 700px)
            and (max-device-width: 900px) {
                .helpfulIcons {
                    height:111.6px; 
                    width: 118.8px;
                }
                #helpfulIconTable {
                    position: relative; 
                    bottom: 170px; 
                    width: 70%;
                    margin-left: auto;
                    margin-right: auto;
                }
                #socialIconTable {
                    position: relative; 
                    bottom: 705px; 
                    width: 40%;
                    left: -8px;

                }
                .socialIcons {
                    height:99.2px; 
                    width: 105.6px; 
                }
                socialCells {
                    padding-right: 5px; 
                    width:25%; 
                    text-align: center;
                }
            }

            @media only screen 
            and (min-device-width: 901px) {
                .helpfulIcons {
                    height:173.6px; 
                    width: 184.8px;
                }
                #helpfulIconTable {
                    position: relative; 
                    bottom: 230px; 
                    width: 90%;
                    margin-left: auto;
                    margin-right: auto;
                }
                #socialIconTable {
                    position: relative; 
                    bottom: 930px; 
                    width: 40%;

                }
                .socialIcons {
                    height: 124px; 
                    width: 132px; 
                }
                .socialCells {
                    padding-right: 10px; 
                    width:25%; 
                    text-align: center;
                }
            }

        </style>
    </head>
    <body id="bodyBg">
        <!--[if gte MSO 9]>
        <table width="411"><tr><td>
        <![endif]-->
        <table id="bgTable" style="width:100%">
            <tr>
                <td>
                    <img src="http://kingtaxsavannah.com/tax-prep/images/phone/bg_411x823.jpg" alt="king tax get social" style="width:100%" />
                    <table id="helpfulIconTable">
                        <tr>
                            <td style="padding-left: 20px; padding-right: 20px; width:33.33%; text-align: center;"><a href="https://sa.www4.irs.gov/irfof/lang/en/irfofgetstatus.jsp" target="_blank"><img alt="IRS Where's My Refund" class="helpfulIcons" src="http://kingtaxsavannah.com/tax-prep/images/phone/icons/irs_icon.png" /></a></td>
                            <td style="padding-right: 20px; width:33.33%; text-align: center;"><a href="https://dor.georgia.gov/wheres-my-refund" target="_blank"><img alt="GA Where's My Refund" class="helpfulIcons" src="http://kingtaxsavannah.com/tax-prep/images/phone/icons/ga_icon.png" /></a></td>
                            <td style="padding-right: 20px; width:33.33%; text-align: center;"><a href="https://mydorway.dor.sc.gov/_/" target="_blank"><img alt="SC Where's My Refund" class="helpfulIcons" src="http://kingtaxsavannah.com/tax-prep/images/phone/icons/sc_icon.png" /></a></td>
                        </tr>                        
                    </table>
                    <table id="socialIconTable">
                        <tr>
                            <td class="socialCells" style="padding-left: 20px;"><a href="https://www.facebook.com/kingtaxsavannah" target="_blank"><img alt="Facebook" class="socialIcons" src="http://kingtaxsavannah.com/tax-prep/images/phone/icons/facebook.png" /></a></td>
                            <td class="socialCells"><a href="https://www.instagram.com/kingtaxsavannah" target="_blank"><img alt="Instagram" class="socialIcons" src="http://kingtaxsavannah.com/tax-prep/images/phone/icons/instagram.png" /></a></td>
                            <td class="socialCells"><a href="https://twitter.com/KingTaxSavannah" target="_blank"><img alt="Twitter" class="socialIcons" src="http://kingtaxsavannah.com/tax-prep/images/phone/icons/linkedin.png" /></a></td>
                            <td class="socialCells"><a href="https://www.linkedin.com/company/kingtaxsavannah" target="_blank"><img alt="Linkedin" class="socialIcons" src="http://kingtaxsavannah.com/tax-prep/images/phone/icons/twitter.png" /></a></td>                            
                        </tr>                        
                    </table>
                </td>
            </tr>
        </table>
        <!--[if gte MSO 9]>
        </td></tr></table>
        <![endif]-->
    </body>
</html>

当我在chrome中打开html文件并在不同的移动设备设置下对其进行测试时,图标显示在我希望它们所在的确切位置。但当我实际将html作为电子邮件发送时,所有的图标都在主图像的下方。

EN

回答 1

Stack Overflow用户

发布于 2019-02-20 12:28:42

谢谢你的评论。我以为Gmail不支持我的css,但事实证明,就像你说的,他们不允许定位。因此,我将我的背景图像设为表格的背景图像,并将图标放置在表格行的单个单元格中。我使用空表行来定位。css通过媒体查询根据设备屏幕的大小调整空表行的高度。就像一种护身符!谢谢!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54741207

复制
相关文章
在HTML中如何使用CSS?
一、前言 在 HTML 中使用 CSS,包括内联式、内嵌式、链接式和导入式。 二、分类 2.1 内联式 内联式是所有样式应用方式中最为直接的一种,它通过对 HTML 标记使用 属性,将 CSS 代码直接写在其中。 内联式是最简单、直接的 CSS 使用方法,但它的针对性很明显,只能作用于当前标记,造成代码冗余,维护比较困难。 2.2 内嵌式 内嵌式与内联式使用方法不同,它将 CSS 代码写在 标记之间,并需要采用 标记进行声明。 使用内嵌式 CSS 用法时 CSS 代码将被集中放在 标记中,这样方便查
企鹅号小编
2018/02/01
8.6K0
CSS媒体查询_css网页
min-width: 800px 表示当屏幕宽度大于等于800px时,该样式生效。
全栈程序员站长
2022/11/01
1.7K0
css媒体查询aspect-ratio宽高比在less中的使用
css媒体查询有一个 宽高比很方便,aspect-ratio ,可以直接使用宽/高 来进行页面适配   使用样例如下:
蓓蕾心晴
2019/08/08
3.1K0
html --- rem 媒体查询
手机屏幕的分辨率越来越高,比如iPhone 5为640*1136 px、iPhone 6/6S为750*1334 px。我拿到的UI图,其参考分辨率为1440*2560 px。
小蔚
2019/09/11
1.5K0
CSS-媒体查询
由于媒体查询需要根据不同的浏览器宽度调整元素的样式, 所以不适合用于比较复杂的网页
程序员 NEO
2023/09/29
2070
CSS-媒体查询
CSS 媒体查询适配
media在引入css时可以加media属性来设置在特定媒体下的样式,但是要注意将其写在所有样式的最下方
圆圆的冬瓜
2022/06/17
1.3K0
css3媒体查询简介
<link rel="stylesheet" media="min-width=900" />
RobinsonZhang
2018/08/28
7600
随方逐圆--全面理解CSS媒体查询
在CSS2中,媒体查询只使用于<style>和<link>标签中,以media属性存在;media属性用于为不同的媒介类型规定不同的样式,而真正广泛使用的媒介类型是'screen'、'print'和'all'
江米小枣
2020/06/15
1.2K0
CSS:使用CSS媒体查询创建响应式布局
  现如今在Web前端领域,BootStrap是一个最流行的UI库,其12列的栅栏系统为响应式布局提供了一种对程序员来说很好操作的模式。
王金龙
2019/02/25
3K0
如何让BYOE在云中为企业工作
目前,在云中使用用户自己的加密产品已变得更为普遍。专家Ed Moyle在本文中讨论了BYOE的优缺点,以及用户在正式实施前所需了解的内容。 花几分钟时间与大多数技术人员讨论下公共云服务,你很快就会得到一个肯定的结论:从安全性的角度来看,云应用具有较大的挑战性。在一定程度上,这是云本身的固有特性决定的。让云变得有价值和强大的原因之一就是先进技术基础的商品化,这就意味着技术堆栈一定层面以下的一切(具体层面高低因云模式不同而不同)在客户眼中就是一个黑盒。这是非常强大的,因为它意味着客户可以重定向资源,否则它将
静一
2018/03/27
3.1K1
如何让BYOE在云中为企业工作
css媒体查询边界值是否包含?
答案:对于 min-width, max-width  这种,是左右边界值都包含的。
蓓蕾心晴
2022/11/18
8300
【说站】css媒体查询的使用
1、尽量把媒体查询放在相关规则附近,不要放在文档底部,否则很容易被后来维护的人遗忘。
很酷的站长
2022/11/24
9210
【说站】css媒体查询的使用
javascript中html当中如何引用css文件
1.html当中如何引用css文件 马克-to-win:css:Cascading Style Sheets 例 1.1 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title></title> <!-- LINK.rel (Property) The relationship between the current element and the remote document. --> <link href="outer.css" rel="stylesheet"> </head> <body> <table width="190" height="80" border="2" > <tr> <td >张三</td> </tr> <tr> <td>qixy</td> </tr> <tr> <td>李四</td> </tr> <tr> <td>王五</td> </tr> </table> </body> </html> outer.css: table { background-color: #0000ff; } td { /*the following statement make the border to show, because of the different color.*/ background-color: #FF0000; }
马克java社区
2019/11/26
2.4K0
javascript中html当中如何引用css文件
如何让 Python 脚本在工作日运行?
你好,我是征哥,最近用 Python 写了个每日签到答题的脚本,想让它在工作日每天运行,于是我找到了这个三方库-chinesecalendar。
somenzz
2022/05/24
3.2K0
如何让 Python 脚本在工作日运行?
在html中加入外部css样式,如何引入CSS样式表?
CSS用于修饰网页样式,但是,如果希望CSS修饰的样式起作用,就必须在html档中引入CSS样式表。引入样式表的常用方式有三种,即行内式、内嵌式、外链式,具体介绍如下。
全栈程序员站长
2022/09/15
2.8K0
在html中加入外部css样式,如何引入CSS样式表?
媒体查询中的条件
在做一个需求的时候遇到一个问题,大概意思是:当屏幕宽度大于某个值的时候,要为容器指定一个高度。
阿年、嗯啊
2021/04/27
2.5K0
在XCode中如何使用高级查询
对于一个框架来说,仅有基本的CURD不行,NewLife.XCode同时还提供了一个非常宽松的方式来使用高级查询,以满足各种复杂的查询需求。 (本文同样适用于其它任何数据访问框架) 先上图看一个复杂查询的效果图: image.png 这里有8个固定的查询条件和1个模糊查询条件,加上多表关联(7张表)、分页、统计,如果用传统的做法,这个查询会非常的复杂。 这个页面有XCode实现,核心查询部分共100多行代码,包括一个查询、一个总记录数分页、两个统计(就是业绩、提成等的统计),看看高级查询代码: image
大石头
2018/01/15
5.1K0
在XCode中如何使用高级查询
电子邮件工作机制
相关的几个协议 -SMTP(Simple Mail Transfer Protocol) -POP(Post Office Protocol) -IMAP(在不同智能终端上管理邮件) 早期的电子邮件是
互联网金融打杂
2018/04/03
1.9K0
电子邮件工作机制
在EF中,如何实现模糊查询?
【摘要】我们知道在sql中,可以通过like方法实现模糊查询。而在EF中,我们通常使用Lambda表达式实现各种复杂的数据查询,那么,类似于sql的like方法如何实现呢?
高一峰
2020/09/22
4.5K0
在EF中,如何实现模糊查询?
点击加载更多

相似问题

CSS媒体查询在HTML电子邮件中不起作用

155

HTML/CSS媒体查询

21

HTML/CSS中的媒体查询

31

HTML/CSS中的媒体查询

14

CSS媒体-查询不工作

22
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文