图像切换响应式HTML电子邮件

时间:2016-05-10 15:55:30

标签: html responsive-design imageswitcher

我正在努力让我的标题图片无缝切换/替换,具体取决于查看的设备。

以前我用过代码来调整大小,使用max-width,min-width等...

我希望在两张图片之间切换,具体取决于移动设备(最大400px)或桌面设备(最少480张)

桌面标题:... phl-headline2.jpg

移动标题(待交换):... phl-headline-320-2.jpg

这是我正在使用的代码......

希望有人有一些见解或答案,说明为什么我目前没有工作。

谢谢!

首次发布

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>PLANET HOME LENDING</title>
<style>
	@media only screen and (min-device-width: 480px) and (max-device-width: 1024px)
	  {
		span[id=switcher] {display:block;
		background-image: url(http://www.johnroebas.com/hosted/phl-headline2.jpg) !important;
		background-repeat: no-repeat !important;
		background-position: center !important;
		width: 590px !important;
		height: 195px !important; }
		img[id=houdini] {display: none !important; }
	}
	@media only screen and (max-device-width: 400px) 
	  {
		span[id=switcher] {display:block;
		background-image: url(http://www.johnroebas.com/hosted/phl-headline-320-2.jpg) !important;
		background-repeat: no-repeat !important;
		background-position: center !important;
		width: 320px !important;
		height: 203px !important; }
		img[id=houdini] {display: none !important; }
	}
</style>
</head>
<body>
<table border="0" align="center" cellpadding="0" cellspacing="0" style="width: 100%; max-width: 590px; min-width: 320px">
  <tbody>
    <tr>
      <td><table border="0" align="center" cellpadding="0" cellspacing="0" style="width: 100%; max-width: 590px; min-width: 320px">
        <tbody>
          <tr>
            <td height="30" bgcolor="#72c045" style="color:#FFFFFF; font-weight:normal; font-size:10px; line-height:12px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:14px; padding-right:8px;">Now you can lower your monthly mortgage payment</td>
          </tr>
          <tr>
            <td height="62"><img src="http://www.johnroebas.com/hosted/phl-logo-320.jpg" alt="Planet Home Lending" style="display:block; width: 100%; max-width: 247px; max-height: 62px; min-width: 300px; -ms-interpolation-mode: bicubic;"></td>
          </tr>
          <tr>
            <td id="switcher"><img id="houdini" src="http://www.johnroebas.com/hosted/phl-headline2.jpg" alt="Good News" style="display:block; -ms-interpolation-mode: bicubic;"></td>
          </tr>
          <tr>
            <td><table width="390" border="0" align="center" cellpadding="0" cellspacing="0">
              <tbody>
                <tr>
                  <td height="18" colspan="2"><img src="http://www.johnroebas.com/hosted/phl-spacer.jpg" width="40" height="18" style="display:block;" align="absbottom"></td>
                </tr>
                <tr>
                  <td height="36" colspan="2" style="color:#0f1752; font-weight:normal; font-size:12px; line-height:18px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:8px; padding-right:8px;">
                  <strong>[FIRST NAME],<br>
                  Good news from Planet Home Lending:</strong></td>
                </tr>
                <tr>
                  <td height="16" colspan="2"><img src="http://www.johnroebas.com/hosted/phl-spacer.jpg" width="40" height="16" style="display:block;" align="absbottom"></td>
                </tr>
                <tr>
                  <td width="28" style="vertical-align:top"><img src="http://www.johnroebas.com/hosted/phl-button.jpg" width="28" height="28" style="display:block;"></td>
                  <td width="362" style="color:#0f1752; vertical-align:bottom; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:8px; padding-right:8px;">
                  We reviewed your account – you may be eligible<br>
                    for a simplified refinance to a lower rate:</td>
                </tr>
                <tr>
                  <td height="10" colspan="2"><img src="http://www.johnroebas.com/hosted/phl-spacer.jpg" width="40" height="10" style="display:block;" align="absbottom"></td>
                </tr>
                <tr>
                  <td colspan="2"><table width="286" border="1" bordercolor="#72c045" align="center" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <td bgcolor="#72c045" style="color:#FFFFFF; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:4px; padding-right:8px;">Your rate after refinancing:</td>
    </tr>
    <tr>
      <td style="color:#0f1752; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:4px; padding-right:8px; padding-bottom:4px; padding-top:2px;"><strong>X.XX%</strong><br>
        (X.XX% Interest Rate)</td>
    </tr>
    <tr>
      <td bgcolor="#72c045" style="color:#FFFFFF; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:4px; padding-right:8px;">New lower monthly payment:</td>
    </tr>
    <tr>
      <td style="color:#0f1752; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:4px; padding-right:8px; padding-bottom:4px; padding-top:2px;"><strong>$X,XXX.XX</strong></td>
    </tr>
    <tr>
      <td bgcolor="#72c045" style="color:#FFFFFF; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:4px; padding-right:8px;">Your possible savings:</td>
    </tr>
    <tr>
      <td style="color:#0f1752; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:4px; padding-right:8px; padding-bottom:4px; padding-top:2px;"><strong>$XXX</strong> per month</td>
    </tr>
  </tbody>
</table>
</td>
                </tr>
                <tr>
                  <td height="10" colspan="2"><img src="http://www.johnroebas.com/hosted/phl-spacer.jpg" width="40" height="10" style="display:block;" align="absbottom"></td>
                </tr>
                <tr>
                  <td width="28" style="vertical-align:top"><img src="http://www.johnroebas.com/hosted/phl-button.jpg" width="28" height="28" align="abstop" style="display:block;"></td>
                  <td width="362" style="color:#0f1752; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:8px; padding-right:8px;">
                  30-year fixed rate, loan amount up to $XXX,XXX</td>
                </tr>
                <tr>
                  <td height="10" colspan="2"><img src="http://www.johnroebas.com/hosted/phl-spacer.jpg" width="40" height="10" style="display:block;" align="absbottom"></td>
                </tr>
                <tr>
                  <td width="28" style="vertical-align:top"><img src="http://www.johnroebas.com/hosted/phl-button.jpg" width="28" height="28" align="abstop" style="display:block;"></td>
                  <td width="362" style="color:#0f1752; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:8px; padding-right:8px;">
                  $0 out-of-pocket closing cost option</td>
                </tr>
                <tr>
                  <td height="10" colspan="2"><img src="http://www.johnroebas.com/hosted/phl-spacer.jpg" width="40" height="10" style="display:block;" align="absbottom"></td>
                </tr>
                <tr>
                  <td width="28" style="vertical-align:top"><img src="http://www.johnroebas.com/hosted/phl-button.jpg" width="28" height="28" align="abstop" style="display:block;"></td>
                  <td width="362" style="color:#0f1752; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:8px; padding-right:8px;">
                  No home appraisal needed</td>
                </tr>
                <tr>
                  <td height="10" colspan="2"><img src="http://www.johnroebas.com/hosted/phl-spacer.jpg" width="40" height="10" style="display:block;" align="absbottom"></td>
                </tr>
                <tr>
                  <td width="28" style="vertical-align:top"><img src="http://www.johnroebas.com/hosted/phl-button.jpg" width="28" height="28" style="display:block;"></td>
                  <td width="362" style="color:#0f1752; vertical-align:bottom; font-weight:normal; font-size:12px; line-height:16px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:8px; padding-right:8px;">
                  No “mortgage mumbo jumbo”– that’s the Planet Home Lending promise!</td>
                </tr>
              </tbody>
            </table></td>
          </tr>
          <tr>
            <td height="18"><img src="http://www.johnroebas.com/hosted/phl-spacer.jpg" width="40" height="18" style="display:block;" align="absbottom"></td>
          </tr>
          <tr>
            <td><img src="http://www.johnroebas.com/hosted/phl_phone.jpg" alt="Call" align="absbottom" style="display:block; width: 100%; max-width: 590px; max-height: 64px; min-width: 300px; -ms-interpolation-mode: bicubic;"></td>
          </tr>
            <tr>
            <td height="8" bgcolor="#e4f3dc"><img src="http://www.johnroebas.com/hosted/phl-spacer2.jpg" width="40" height="8" style="display:block;" align="absbottom"></td>
          </tr>
          <tr>
            <td bgcolor="#e4f3dc" style="color:#000000; font-weight:normal; font-size:8px; line-height:12px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:14px; padding-right:14px;">
            THIS OFFER IS NOT BEING MADE BY AN AGENCY OF THE US GOVERNMENT.  PLANET HOME LENDING IS NOT AFFILIATED WITH ANY  GOVERNMENT ENTITY.  
</td>
          </tr>
                    <tr>
            <td height="8" bgcolor="#e4f3dc"><img src="http://www.johnroebas.com/hosted/phl-spacer2.jpg" width="40" height="8" style="display:block;" align="absbottom"></td>
          </tr>
                    <tr>
            <td bgcolor="#e4f3dc" style="color:#000000; font-weight:normal; font-size:8px; line-height:12px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:14px; padding-right:14px;">
            THE PRODUCTS AND SERVICES DESCRIBED HEREIN HAVE NOT BEEN APPROVED OR ENDORSED BY ANY GOVERNMENTAL AGENCY.</td>
          </tr>
                    <tr>
            <td height="8" bgcolor="#e4f3dc"><img src="http://www.johnroebas.com/hosted/phl-spacer2.jpg" width="40" height="8" style="display:block;" align="absbottom"></td>
                      </tr>
                    <tr>
            <td bgcolor="#e4f3dc" style="color:#000000; font-weight:normal; font-size:8px; line-height:12px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:14px; padding-right:14px;">
            Monthly payment is based on your current unpaid principal balance of $XXX,XXX.XX. Terms are based on a 30-year Fixed Rate Loan. Actual terms may vary based on loan product. Advertised monthly payment reflects principal and interest payments only and does not include insurance and tax premiums.  </td>
          </tr>
                    <tr>
            <td height="8" bgcolor="#e4f3dc"><img src="http://www.johnroebas.com/hosted/phl-spacer2.jpg" width="40" height="8" style="display:block;" align="absbottom"></td>          
            </tr>
                    <tr>
            <td bgcolor="#e4f3dc" style="color:#000000; font-weight:normal; font-size:8px; line-height:12px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:14px; padding-right:14px;">
            Total monthly payments will be higher. Other terms and restrictions may apply. Please call for details.</td>
          </tr>
          <tr>
            <td height="8" bgcolor="#e4f3dc"><img src="http://www.johnroebas.com/hosted/phl-spacer2.jpg" width="40" height="8" style="display:block;" align="absbottom"></td>          
            </tr>
                    <tr>
            <td bgcolor="#e4f3dc" style="color:#000000; font-weight:normal; font-size:8px; line-height:12px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:14px; padding-right:14px;">
            Monthly possible savings amount is based on the difference between your current principal and interest payment and the proposed principal and interest payment as shown in this letter. Monthly payments do not include insurance and tax premiums and, therefore, your monthly savings may be less. Please call for details.</td>
          </tr>
                    <tr>
            <td height="8" bgcolor="#e4f3dc"><img src="http://www.johnroebas.com/hosted/phl-spacer2.jpg" width="40" height="8" style="display:block;" align="absbottom"></td>          
            </tr>
                    <tr>
            <td bgcolor="#e4f3dc" style="color:#000000; font-weight:normal; font-size:8px; line-height:12px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:14px; padding-right:14px;">
            You must be at least 18 years of age to apply. You may be required to meet eligibility criteria including (but not limited to), the following: that your loan be secured by your primary residence; that you meet minimum credit score benchmark, credit history and mortgage payment history requirements; that you are currently employed; and that your combined monthly debts and other credit obligations are not excessive in relation to your verifiable gross monthly income.</td>
          </tr>
                    <tr>
            <td height="8" bgcolor="#e4f3dc"><img src="http://www.johnroebas.com/hosted/phl-spacer2.jpg" width="40" height="8" style="display:block;" align="absbottom"></td>          
            </tr>
                    <tr>
            <td bgcolor="#e4f3dc" style="color:#000000; font-weight:normal; font-size:8px; line-height:12px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:14px; padding-right:14px;">
            Equal Housing Lender. Planet Home Lending, LLC NMLS ID # 17022</td>
          </tr>
                    <tr>
            <td height="8" bgcolor="#e4f3dc"><img src="http://www.johnroebas.com/hosted/phl-spacer2.jpg" width="40" height="8" style="display:block;" align="absbottom"></td>          
            </tr>
                    <tr>
            <td bgcolor="#e4f3dc" style="color:#000000; font-weight:normal; font-size:8px; line-height:12px; font-family: verdana, open sans, helvetica, gill sans, sans-serif; padding-left:14px; padding-right:14px;">(www.nmlsconsumeraccess.org). Headquarters located at 321 Research Parkway, Suite 303, Meriden, CT 06450. AZ Mortgage Banker License MB-0929069, Licensed by the Department of Business Oversight under the California Residential Mortgage Lending license #: 4130947, Georgia Residential Mortgage Licensee #24035, Illinois Residential Mortgage Licensee, Licensed by the Mississippi Department of Banking and Consumer Finance, Licensed by the New Hampshire Banking Department, OH Mortgage Broker Act Mortgage Banker Exemption MBMB.850161.000, OR Mortgage Lending License ML-5147, Rhode Island Licensed Lender, Licensed by the N.J. Department of Banking and Insurance, TX SML Mortgage Banker, WA Consumer Loan Company License CL-17022</td>
          </tr>
                    <tr>
            <td bgcolor="#e4f3dc">&nbsp;</td>
          </tr>
        </tbody>
      </table></td>
    </tr>
  </tbody>
</table>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您需要将两个图像添加到其中一个表格单元格中并对它们进行分类。然后,我们可以使用媒体查询在display:block;display:none;

之间切换

HTML

<tr>
    <td>
        <img id="desktop" src="http://www.johnroebas.com/hosted/phl-headline2.jpg" alt="Good News" style="-ms-interpolation-mode: bicubic;">
        <img id="mobile" src="http://www.johnroebas.com/hosted/phl-headline-320-2.jpg" alt="Good News" style="-ms-interpolation-mode: bicubic;">
    </td>
</tr>

CSS(在您的样式块中)

img#mobile{
    display:none;
}

@media only screen and (max-width: 480px){
    img#mobile{
        display:block !important;
    }
    img#desktop{
        display:none !important;
    }
}

这里的工作示例

http://codepen.io/jcoulterdesign/pen/6ae61ee4abda054b15ce9c99fea3452c