【发布时间】:2020-10-27 03:54:03
【问题描述】:
在处理 HTML 电子邮件时,我需要表格的高度与移动设备的宽度相匹配。使用的背景图像具有 1:1 的纵横比。背景需要填充设备的宽度,因此表格的高度需要与移动设备的宽度相匹配。这两个盒子在移动设备上堆叠。
td {font-family: Helvetica;}
@media only screen and (max-width:414px){
.bg {
width: 100% !important;
background-size: cover !important;
background-position: center top !important;
background-repeat: no-repeat !important;
display: block !important;
}
.imgWidth {
width: 100%!important;
height: auto !important;
min-width: 100%!important
}
.fullWidth {
width: 100%!important;
min-width: 100%!important
}}
<table cellpadding="0" cellspacing="0" width="600" align="center" class="fullWidth">
<tr>
<td width="600" class="fullWidth">
<table align="left" cellpadding="0" cellspacing="0" class="fullWidth" width="300" height="300">
<tr>
<td class="fullWidth"><img src="https://dummyimage.com/300x300/c9c9c9/939396" style="display:block;" width="100%" class="imgWidth" border="0" /></td>
</tr>
</table>
<!-- height of below table (red box) needs to match width of device -->
<table align="left" cellpadding="0" cellspacing="0" class="bg" width="300" height="300" background="https://dummyimage.com/300x300/de4811/e0fbff">
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr><td>Hello world</td></tr>
<tr><td>Hello world 2</td></tr>
<tr><td>Hello world 3</td></tr>
</table>
</td>
</tr>
</table>
<!-- end -->
</td>
</tr>
</table>
在上面的例子中,红框表格的高度是可变的。是否可以让红色框的高度与移动设备的宽度相匹配,从而显示完整的背景?
【问题讨论】:
-
不要认为这是可能的。几乎每台设备都会在图像周围为您提供边距/填充。
标签: html css html-email