Fluid Design Max-Width Changing To 100% On Break (HTML EMAIL)

206 Views Asked by At

I found this related question that has a great solution where there is a two column design that stacks upon reaching the threshold of 320px. This is great; however, I'm curious if there's a way to use a width property in order to replicate this behavior of two columns stacking, but instead of the widths being constrained to 320px, they become width 100% after stacking on each other. The question can be found here: How to make html email responsive in gmail?

and the code can be found below

<!doctype html>
<html>
    <body style="margin:0;">
        <center>
            <table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">




                <!-- // 2-COLUMN SCAFFOLD [CENTERING, FLUID] -->
                <tr>
                    <td align="center" height="100%" valign="top" width="100%">
                        <!--[if mso]>
                        <table align="center" border="0" cellspacing="0" cellpadding="0" width="660">
                        <tr>
                        <td align="center" valign="top" width="660">
                        <![endif]-->
                        <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:660px;">
                            <tr>
                                <td align="center" valign="top" style="font-size:0;">
                                    <!--// DEVELOPER NOTES:
                                        1. Setting font-size:0; is necessary to ensure
                                           that there is no extra spacing introduced
                                           between the centering divs that wrap each
                                           of the columns. //-->

                                    <!--[if mso]>
                                    <table align="center" border="0" cellspacing="0" cellpadding="0" width="660">
                                    <tr>
                                    <td align="left" valign="top" width="330">
                                    <![endif]-->
                                    <div style="display:inline-block; max-width:50%; min-width:240px; vertical-align:top; width:100%;">
                                        <!--// DEVELOPER NOTES:
                                            1. To have each column center upon stacking,
                                               wrap them in individual divs, set the same
                                               max-width and width as the table within it,
                                               and set display to inline-block; using
                                               vertical-align is optional.

                                            2. Setting min-width determines when the two
                                               columns of this block will wrap; in this
                                               case, when the total available width is
                                               less than or equal to 480px. //-->

                                        <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:330px;">
                                            <tr>
                                                <td align="center" valign="top">

                                                    <!-- // REPLACE WITH BLOCK -->
                                                    <p style="background-color:#2BAADF; color:#FFFFFF; font:16px Helvetica, sans-serif, normal; margin:0 !important; padding:10px;">LEFT</p>
                                                    <!-- REPLACE WITH BLOCK // -->

                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                    <!--[if mso]>
                                    </td>
                                    <td align="left" valign="top" width="330">
                                    <![endif]-->
                                    <div style="display:inline-block; max-width:50%; min-width:240px; vertical-align:top; width:100%;">
                                        <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:330px;">
                                            <tr>
                                                <td align="center" valign="top">

                                                    <!-- // REPLACE WITH BLOCK -->
                                                    <p style="background-color:#51BBE5; color:#FFFFFF; font:16px Helvetica, sans-serif, normal; margin:0 !important; padding:10px;">RIGHT</p>
                                                    <!-- REPLACE WITH BLOCK // -->  

                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                    <!--[if mso]>
                                    </td>
                                    </tr>
                                    </table>
                                    <![endif]-->
                                </td>
                            </tr>
                        </table>
                        <!--[if mso]>
                        </td>
                        </tr>
                        </table>
                        <![endif]-->
                    </td>
                </tr>
                <!-- 2-COLUMN SCAFFOLD [CENTERING, FLUID] // -->




            </table>
        </center>
    </body>
</html>

I recommend testing it out to see what I'm referring to. Any advice would be appreciated, thanks!

1

There are 1 best solutions below

2
On

I believe this is what you are looking for. You can use media queries to target specific HTML elements with a class. I have given a class of FullWidth and when the screens size reaches 480 pixels, the blocks will be full width of the screen.

A few things to note:

  • This code will work on latest Gmail app, iOS (generic email client) and Android 4.4 and below(generic email client).
  • Move the media query into the head of the HTML.

@media only screen and (max-width:480px) {
.FullWidth{width:100% !important;max-width:100% !important;}
}
<!doctype html>

<html>
<body style="margin:0;">
        <center>
            <table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
                <!-- // 2-COLUMN SCAFFOLD [CENTERING, FLUID] -->
                <tr>
                    <td align="center" height="100%" valign="top" width="100%">
                        <!--[if mso]>
                        <table align="center" border="0" cellspacing="0" cellpadding="0" width="660">
                        <tr>
                        <td align="center" valign="top" width="660">
                        <![endif]-->
                        <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:660px;">
                            <tr>
                                <td align="center" valign="top" style="font-size:0;">
                                    <!--// DEVELOPER NOTES:
                                        1. Setting font-size:0; is necessary to ensure
                                           that there is no extra spacing introduced
                                           between the centering divs that wrap each
                                           of the columns. //-->

                                    <!--[if mso]>
                                    <table align="center" border="0" cellspacing="0" cellpadding="0" width="660">
                                    <tr>
                                    <td align="left" valign="top" width="330">
                                    <![endif]-->
                                    <div style="display:inline-block; max-width:50%; min-width:240px; vertical-align:top; width:100%;" class="FullWidth">
                                        <!--// DEVELOPER NOTES:
                                            1. To have each column center upon stacking,
                                               wrap them in individual divs, set the same
                                               max-width and width as the table within it,
                                               and set display to inline-block; using
                                               vertical-align is optional.

                                            2. Setting min-width determines when the two
                                               columns of this block will wrap; in this
                                               case, when the total available width is
                                               less than or equal to 480px. //-->

                                        <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:330px;" class="FullWidth">
                                            <tr>
                                                <td align="center" valign="top">

                                                    <!-- // REPLACE WITH BLOCK -->
                                                    <p style="background-color:#2BAADF; color:#FFFFFF; font:16px Helvetica, sans-serif, normal; margin:0 !important; padding:10px;">LEFT</p>
                                                    <!-- REPLACE WITH BLOCK // -->

                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                    <!--[if mso]>
                                    </td>
                                    <td align="left" valign="top" width="330">
                                    <![endif]-->
                                    <div style="display:inline-block; max-width:50%; min-width:240px; vertical-align:top; width:100%;" class="FullWidth">
                                        <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:330px;" class="FullWidth">
                                            <tr>
                                                <td align="center" valign="top">

                                                    <!-- // REPLACE WITH BLOCK -->
                                                    <p style="background-color:#51BBE5; color:#FFFFFF; font:16px Helvetica, sans-serif, normal; margin:0 !important; padding:10px;">RIGHT</p>
                                                    <!-- REPLACE WITH BLOCK // -->  

                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                    <!--[if mso]>
                                    </td>
                                    </tr>
                                    </table>
                                    <![endif]-->
                                </td>
                            </tr>
                        </table>
                        <!--[if mso]>
                        </td>
                        </tr>
                        </table>
                        <![endif]-->
                    </td>
                </tr>
                <!-- 2-COLUMN SCAFFOLD [CENTERING, FLUID] // -->




            </table>
        </center>
    </body>
</html>

Let me know if any questions

Cheers