我目前正在使用 MJML 创建响应式电子邮件。我遇到的困难不是 MJML 本身的问题,而是更多关于某些不支持媒体查询/样式的电子邮件客户端,所以我不确定如何创建一种有效的方式来显示桌面和移动视图的不同图像。
到目前为止,这是我的代码:
<mjml>
<mj-head>
<mj-style inline="inline">
.show_on_desktop,
.show_on_desktop-outlook {
display: none;
}
.show_on_desktop,
.show_on_desktop-outlook {
mso-hide: all;
}
</mj-style>
<mj-style>
@media only screen and (min-width:480px) {
.show_on_desktop {
display: block !important;
}
.show_on_mobile,
.show_on_mobile-outlook {
display: none !important;
}
}
</mj-style>
</mj-head>
<mj-body>
<mj-section css-class="show_on_desktop" padding="0">
<mj-column css-class="show_on_desktop" padding="0">
<mj-image src="https://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg" alt="" padding="0">
</mj-image>
</mj-column>
</mj-section>
<mj-section css-class="show_on_mobile" padding="0">
<mj-column css-class="show_on_mobile" padding="0">
<mj-image src="https://beebom.com/wp-content/uploads/2016/01/Reverse-Image-Search-Engines-Apps-And-Its-Uses-2016.jpg" alt="" padding="0">
</mj-image>
</mj-column>
</mj-section>
</mj-body>
</mjml>
你可以在这里现场试用:https ://mjml.io/try-it-live/37hvh_Ss0M7