Aligning table elements for optimal responsiveness

Need a hand with my HTML email code. I'm struggling to center the "resort boxes" when viewed on smaller screens like phones. Tried everything but can't crack it. Appreciate any help!

https://i.sstatic.net/V6Rdr.jpg

<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"><!--[if !mso]><!-->
    <meta content="IE=edge" http-equiv="X-UA-Compatible"><!--<![endif]-->
    <meta content="width=device-width, initial-scale=1.0" name="viewport">

    <title>
    </title>
    <style type="text/css">

           @media only screen and (max-width: 480px) {
           body,table,td,p,a,li,blockquote {
           -webkit-text-size-adjust:none !important;
           font-size:90%;
           }
           table {width: 100% !important;}
           .responsive-image img {
           height: auto !important;
           max-width: 100% !important;
           width: 100% !important;
           }

           }   


    table {border-collapse: collapse;}

           /* Basics */
    body {
       margin: 0 !important;
       padding: 0;
       background-color: #e4e4e4;
    }
    table {
       border-spacing: 0;
       font-family: sans-serif;
       color: #333333;
    }
    td {
       padding: 0;

    }
    img {
       border: 0;
       max-width: 100%; 
       display:block; 
       height: auto;
    }
    div[style*="margin: 16px 0"] { 
       margin:0 !important;
    }
    .wrapper {
       width: 100%;
       table-layout: fixed;
       -webkit-text-size-adjust: 100%;
       -ms-text-size-adjust: 100%;
    }
    .webkit {
       max-width: 600px;
       margin: 0 auto;
    }

    a {
    text-decoration: none;
    }

    .more a {

       color: white;
       text-decoration: underline;
       line-height: 2em;
       font-family:  sans-serif;

               }
       /*box text content*/
        .resort-name{color: #000000; font-size:20px;  line-height: 1em; font-family: sans-serif;text-align: center}
        .city {color: #615657; font-size:12px;text-align: center}
        .rate {color: #758b1d; font-size:20px; text-align: center}
        .rate-s {color:#969696; text-align: center}

    div.cont table 
    {
       margin: 0 auto; 

    }

    </style>
</head>

<body style="background-color: #e4e4e4">
    <center class="wrapper">
       
        <footer>
            <table align="center" cellpadding="0" cellspacing="0" style="background-color:#63656b;display:table;" width="600">
                <tr>
                    <td height="15" style="font-size: 0; line-height: 0;">
                    </td>
                </tr>


                <tr>
                    <td style="padding:20;">
                        <blockquote>
                            <p style="color:#ffffff; font-size:10px; font-family:Arial, sans-serif; text-align:left;">Terms and Conditions:<br>
                            PROMO CODE: CALI. Valid for new reservations booked between 5/3/2017 - 5/12/2017 for travel from 5/3/2017 - 8/31/2017. Please enter promo code CALI when making your
                            online booking to receive best available rate. Offer is based on availability and may not be available on all room types, Rates may be higher during holiday/event periods
                            and weekends. Cannot be combined with other offers and promotions and is subject to change without notice.</p>
                        </blockquote>
                    </td>
                </tr>


                <tr bgcolor="#63656B">
                    <td colspan="1" rowspan="1" style="padding:20px;color:#000000;">
                        <table align="center" bgcolor="#63656B" border="0" cellpadding="0" cellspacing="0" style="background-color:#63656B;margin-bottom:10px;" width="600px">
                            <tr>
                                <td colspan="1" rowspan="1" style="color:#ffffff;font-weight:normal;vertical-align:top;font-size:12px;font-family:Helvetica, Arial, sans-serif;line-;text-align:center;"
                                valign="top">
                                    <div style="line-height: 2em; display: inline;">
                                        <center>
                                            <a class="imgCaptionAnchor" href=
                                            "http://r20.rs6.net/tn.jsp?f=001VYiWL5i82Ann9qRcISgE6Vp48wcxwnCtzt3iPLVLHE1Nb2KStjtSlaZpsSubBK-vW90CHuojdBnC8cqIWSmfwEfEosTJw_00x6b3LPt2nIOrLNT6cYshOKU511zD5sDgXwusveQqP6VGDBwGiG1Mv-fBkTEz9VTNaBX1_tVKgEQ7cQjl_S28CQ==&c=&ch="
                                            shape="rect" target="_blank"><img alt="Vacation Resorts International" border="0" height="24" hspace="0" src=
                                            "http://www.8664myvacation.com/eguest/images/vri-logo-footer.gif" vspace="0" width="40"></a><br>
                                            <a href="#" shape="rect" style="color:rgb(255, 255, 255);font-weight:normal;text-decoration:none;">25510 Commercentre Dr., Suite 100<br>
                                            Lake Forest, CA 92630<br>
                                            866-469-8222</a><br>
                                            &#169;2017 Vacation Resorts International
                                        </center>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <!-- End 4 Columns -->


            <div class="" style="height: 40px; margin:0 auto; background-color: #e4e4e4; width: 100%">
                &nbsp;
            </div>
            <!-- spacer -->
        </footer>
    </center>
</body>
</html>

Answer №1

Your tr's are already set to display: inline-block; with a defined width within the box, so adding text-align: center on the parent element will center those elements.

<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"><!--[if !mso]><!-->
    <meta content="IE=edge" http-equiv="X-UA-Compatible"><!--<![endif]-->
    <meta content="width=device-width, initial-scale=1.0" name="viewport">

    <title>
    </title>
    <style type="text/css">

           @media only screen and (max-width: 480px) {
           body,table,td,p,a,li,blockquote {
           -webkit-text-size-adjust:none !important;
           font-size:90%;
           }
           table {width: 100% !important;}
           .responsive-image img {
           height: auto !important;
           max-width: 100% !important;
           width: 100% !important;
           }

           }   


    table {border-collapse: collapse;}

           /* Basics */
    body {
       margin: 0 !important;
       padding: 0;
       background-color: #e4e4e4;
    }
    table {
       border-spacing: 0;
       font-family: sans-serif;
       color: #333333;
    }
    td {
       padding: 0;

    }
    img {
       border: 0;
       max-width: 100%; 
       display:block; 
       height: auto;
    }
    div[style*="margin: 16px 0"] { 
       margin:0 !important;
    }
    .wrapper {
       width: 100%;
       table-layout: fixed;
       -webkit-text-size-adjust: 100%;
       -ms-text-size-adjust: 100%;
    }
    .webkit {
       max-width: 600px;
       margin: 0 auto;
    }

    a {
    text-decoration: none;
    }

    .more a {

       color: white;
       text-decoration: underline;
       line-height: 2em;
       font-family:  sans-serif;

               }
       /*box text content*/
        .resort-name{color: #000000; font-size:20px;  line-height: 1em; font-family: sans-serif;text-align: center}
        .city {color: #615657; font-size:12px;text-align: center}
        .rate {color: #758b1d; font-size:20px; text-align: center}
        .rate-s {color:#969696; text-align: center}

    div.cont table 
    {
       margin: 0 auto; 

    }

    </style>
</head>

<body style="background-color: #e4e4e4">
    <center class="wrapper">
        <div class="webkit" style="background-color:#010044">
            <!-- VRI Logo-->

            <table align="center" bgcolor="#E4E4E4" cellpadding="0" cellspacing="0" width="600px">
                <tr>
                    <td><a href="http://www.8664myvacation.com"><img alt="vri-logo" src=
                    "https://mlsvc01-prod.s3.amazonaws.com/483a2626be/f0966faf-85e8-4138-85cc-c5bacc31694e.png?ver=1492203807000" style="padding: 40px 0 15px 5px"></a>
                    </td>
                </tr>
            </table>
            <!-- Insert Header Here -->

            <table align="center" cellpadding="0" cellspacing="0" width="600px">
                <tr align="justify">
                    <td><img alt="HEADER_IMG" class="header" src="https://mlsvc01-prod.s3.amazonaws.com/483a2626be/93869145-c989-4ae6-a9ce-6b48201903ab.jpg?ver=1493324994000">
                    </td>
                </tr>
            </table>
            <!-- End Promo Code Section -->
            <!-- Promo Code Section -->


            <table align="center" cellpadding="0" cellspacing="0" style="background-color:#010044" width="600">
                <tr>
                    <td>
                        <h1 align="center" style="color: white; font-family:'Julius Sans One', sans-serif;">Promo Code: CALI</h1>
                    </td>
                </tr>
            </table>
            <!-- End Promo Code Section -->
            <!-- Resort Section-->


            <div class="container resort-section">
                <table align="center" cellpadding="0" cellspacing="0" width="95%" style="text-align: center;">
                    <tbody>
                        <!-- Resort 1-->


                        <tr style="background-color: white; max-width: 270px; display: inline-block; margin: 7.5px;">
                            <td>
                                <a href="http://www.8664myvacation.com/rentResortInfoSheets.php?prop=tsr&promo=CALI" target="_blank"><img alt="Tahoe Seasons Resort" src=
                                "https://mlsvc01-prod.s3.amazonaws.com/483a2626be/daabeb63-91a4-4c04-9811-b5b42d74ca58.png?ver=1483132264000" style="width: 270;" title="Tahoe Seasons Resort"></a>

                                <div style="padding:10px; text-align: center; valign: top; line-height: 1.25em;">
                                    <!-- Resort name & city info --><span class="resort-name"><strong>Tahoe Seasons Resort</strong></span><br>
                                    <span class="city">S. Lake Tahoe, CA</span> <!-- End resort name & city info -->
                                     <!-- Horizontal rule -->

                                    <hr style="width: 20%; align: center; margin-bottom: 10px">
                                    <!-- End horizontal rule -->
                                    <!-- Resort strikethrough rate --><span style="color: #000000; font-size:16px"><b>From</b> <s style="color:#969696">$122/night</s><br>
                                    <br></span> <!-- End resort special rate -->
                                     <!-- Resort special rate -->
                                    <span style="color: #758b1d; font-size:20px"><b>$98/night</b></span> <<!-- End resort special rate -->
                                </div>
                            </td>
                        </tr>
                        <!-- End Resort 1 -->
                        <!-- Resort 2-->


                        <tr style="background-color: white; max-width: 270px; display: inline-block; margin: 7.5px;">
                            <td>
                                <a href="http://www.8664myvacation.com/rentResortInfoSheets.php?prop=tsr&promo=CALI" target="_blank"><img alt="Tahoe Seasons Resort" src=
                                "https://mlsvc01-prod.s3.amazonaws.com/483a2626be/daabeb63-91a4-4c04-9811-b5b42d74ca58.png?ver=1483132264000" style="width: 270;" title="Tahoe Seasons Resort"></a>

                                <div style="padding:10px; text-align: center; valign: top; line-height: 1.25em;">
                                    <!-- Resort name & city info --><span class="resort-name"><strong>Tahoe Seasons Resort</strong></span><br>
                                    <span class="city">S. Lake Tahoe, CA</span> <!-- End resort name & city info -->
                                     <!-- Horizontal rule -->

                                    <hr style="width: 20%; align: center; margin-bottom: 10px">
                                    <!-- End horizontal rule -->
                                    <!-- Resort strikethrough rate --><span style="color: #000000; font-size:16px"><b>From</b> <s style="color:#969696">$122/night</s><br>
                                    <br></span> <<!-- End resort special rate -->
                                     <!-- Resort special rate -->
                                    <span style="color: #758b1d; font-size:20px"><b>$98/night</b></span> <<!-- End resort special rate -->
                                </div>
                            </td>
                        </tr>
                        <!-- End Resort 2 -->
                    </tbody>
                </table>
                <!-- ADS SECTION-->


                <table align="center" cellpadding="0" cellspacing="0" style="background-color:#010044" width="600">
                    <tr>
                        <td align="center" colspan="2" style="width: 275px; padding: 10px"><a href="http://www.8664myvacation.com/rentHome.php" target="_blank"><img alt="VRI_Ad" height="" src=
                        "https://mlsvc01-prod.s3.amazonaws.com/483a2626be/24f8c582-4b04-4af6-9da6-2b0a182b54bf.png?ver=1486058446000" width="560"></a>
                        </td>
                    </tr>


                    <tr>
                        <td align="center" colspan="2" style="width: 275px; padding: 10px;"><a href="https://www.avis.com/car-rental/profile/go.ac?D415600" target="_blank"><img alt="Avis_Ad.jpg"
                        height="" src="https://cdn2.hubspot.net/hubfs/401702/Avis_Ad.jpg" width="560"></a>
                        </td>
                    </tr>
                </table>
                <!-- START FOOTER=-->


                <footer>
                    <table align="center" cellpadding="0" cellspacing="0" style="background-color:#63656b;display:table;" width="600">
                        <tr>
                            <td height="15" style="font-size: 0; line-height: 0;">
                            </td>
                        </tr>


                        <tr>
                            <td style="padding:20;">
                                <blockquote>
                                    <p style="color:#ffffff; font-size:10px; font-family:Arial, sans-serif; text-align:left;">Terms and Conditions:<br>
                                    PROMO CODE: CALI. Valid for new reservations booked between 5/3/2017 - 5/12/2017 for travel from 5/3/2017 - 8/31/2017. Please enter promo code CALI when making your
                                    online booking to receive best available rate. Offer is based on availability and may not be available on all room types, Rates may be higher during holiday/event periods
                                    and weekends. Cannot be combined with other offers and promotions and is subject to change without notice.</p>
                                </blockquote>
                            </td>
                        </tr>


                        <tr bgcolor="#63656B">
                            <td colspan="1" rowspan="1" style="padding:20px 0px;color:#000000;">
                                <table align="center" bgcolor="#63656B" border="0" cellpadding="0" cellspacing="0" style="background-color:#63656B;margin-bottom:10px;" width="600px">
                                    <tr>
                                        <td colspan="1" rowspan="1" style="color:#ffffff;font-weight:normal;vertical-align:top;font-size:12px;font-family:Helvetica, Arial, sans-serif;line-;text-align:center;"
                                        valign="top">
                                            <div style="line-height: 2em; display: inline;">
                                                <center>
                                                    <a class="imgCaptionAnchor" href=
                                                    "http://r20.rs6.net/tn.jsp?f=001VYiWL5i82Ann9qRcISgE6Vp48wcxwnCtzt3iPLVLHE1Nb2KStjtSlaZpsSubBK-vW90CHuojdBnC8cqIWSmfwEfEosTJw_00x6b3LPt2nIOrLNT6cYshOKU511zD5sDgXwusveQqP6VGDBwGiG1Mv-fBkTEz9VTNaBX1_tVKgEQ7cQjl_S28CQ==&c=&ch="
                                                    shape="rect" target="_blank"><img alt="Vacation Resorts International" border="0" height="24" hspace="0" src=
                                                    "http://www.8664myvacation.com/eguest/images/vri-logo-footer.gif" vspace="0" width="40"></a><br>
                                                    <a href="#" shape="rect" style="color:rgb(255, 255, 255);font-weight:normal;text-decoration:none;">25510 Commercentre Dr., Suite 100<br>
                                                    Lake Forest, CA 92630<br>
                                                    866-469-8222</a><br>
                                                    &#169;2017 Vacation Resorts International
                                                </center>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                    <!-- End 4 Columns -->


                    <div class="" style="height: 40px; margin:0 auto; background-color: #e4e4e4; width: 100%">
                         
                    </div>
                    <!-- spacer -->
                </footer>
            </div>
        </div>
    </center>
</body>
</html>

Answer №2

To center align text on a specific screen, utilize the property with td and employ media queries.

td (text-align:center)

It is recommended to steer clear of inline styles and opt for using styles in a CSS file instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a Radial/Pie Menu using CSS3: A Step-by-Step Guide

I am interested in creating a radial menu using CSS3 transforms animations, similar to the example shown on this Wikipedia page or the flash version demonstrated on this website. Although there is a jQuery implementation available using canvas called Radme ...

The number of contents determines the dynamic CSS border style

Could you please assist me in identifying what this design element is called? I have tried searching on Google, but had no luck finding exactly what I am looking for. Here is an example of the look I am aiming for: https://i.sstatic.net/AXUvq.jpg Can so ...

`Is it possible to animate the rotation of an image within an input control?`

After coming across this helpful answer, I successfully added a rotating GIF image as an icon inside an INPUT control on its right side. Simply applying the "busy" class to my control did the trick, and now it looks like it's in progress. input.busy { ...

Personalizing the structure of a joomla template

Having some trouble customizing my Helix Framework template. I'm trying to adjust the width of the page to be 1140 px. When I make changes in the framework menu, it only adjusts the text field width and not the graphics. How can I achieve the layout s ...

The code functions perfectly on JSfiddle, but for some reason it halts when implemented on

Unfortunately, the code that was working perfectly on JSfiddle seems to be encountering issues when implemented on a regular HTML site. The content loads fine but there seems to be an error with the preview function after selecting an image. We have colla ...

Bring the URL back to its original state upon refreshing the page

A form was created using a combination of HTML and PHP on my website. This specific form takes a number as input, adds 2 to that number, and then displays the result. For instance, if the user enters the number 5 and clicks the submit button, the page wil ...

Creating a visually appealing multi-bar chart in AngularJS: Tips for effectively presenting data

Imagine that I have the JSON data below: [ { month: "Jan", cost: 80, energy: 90 }, { month: "Feb", cost: 50, energy: 80 }, { month: ...

Mapping the preselected values of multiple input fields into an array in Angular 6: A step-by-step guide

When submitting a form with input fields, I need to capture the selected values into an array format like {"userid":1,"newstatus":[1],"mygroup":[1,2,3]}. I attempted using ngmodel but encountered issues. Below is the code snippet: home.component.html & ...

What is the best method to update numerous low-resolution image sources with higher resolution images once they have finished loading?

I'm currently developing a website that implements a strategy of loading low-resolution images first, and then swapping them for high-resolution versions once they are fully loaded. By doing this, we aim to speed up the initial loading time by display ...

Tips on avoiding blurring when making an autocomplete selection

I am currently working on a project to develop an asset tracker that showcases assets in a table format. One of the features I am implementing is the ability for users to check out assets and have an input field populated with the name of the person author ...

Bootstrap 5 introduces a new feature where col-sm-6 will take precedence over col-md

When using Bootstrap 5, I encountered an issue where the columns were not sizing evenly in a row. Specifically, on small screens, I wanted them to be exactly size 6. In this case, the columns should have been size 3 for screens larger than md, but they end ...

When trying to submit a form, encountering an `Uncaught ReferenceError` due to calling ajax within

Attempting to trigger an ajax function within a form in order to retrieve a value for the dropdown. mypython.py @app.route('/new_data', methods = ['POST', 'GET']) def new_data(): #Filter data and return the data(data_lis ...

Center Checkboxes in Bootstrap 4 Form Input

I am working with a Bootstrap Form that contains checkboxes. One specific scenario involves a large number of options to choose from. Currently, these options are displayed in a single long list, which can make it difficult for users to read and select the ...

Heading made of ribbon without increasing the scrolling space

Incorporating a unique ribbon-style heading that stretches out from the content area on both sides to create a 3D effect using an image background without relying on CSS3 techniques. I experimented with floating elements, negative margins, and relative po ...

Numerous criteria for selecting a checkbox

I am working with a student database table called student_db, which looks like this: Name Gender Grade City John Male 2 North Dave Male 4 North Garry Male 3 North Chirsty Female 5 East Monica Female 4 East Andrew Male ...

Tips for showing form data upon click without refreshing the webpage

Whenever I input data into the form and click on the calculate button, the result does not appear in the salary slip box at the bottom of the form. However, if I refresh the page and then click on the calculate button, the results are displayed correctly ...

Issue with Bootstrap 4 list items not displaying in block format

Based on the information from , using li tags as block elements should result in a vertical menu. However, with Bootstrap 4, when I use li tags, the menu stays horizontal on toggle for small devices. Is this the expected behavior? <ul class="nav navb ...

Is there a way to align the mat card title and subtitle on a single line?

My code is utilizing Angular material and here is the HTML snippet: <mat-card> <mat-card-header *ngFor="let club of result[0]"> <mat-card-title>{{club.clubName}}</mat-card-title> <mat-card-subtitle>Clu ...

List of items:1. The first item is elevated in its position

Can anyone explain why the first li item is displaying higher than the rest when I assign an id or class to the div element? Take a look at the code snippet below: <div id="pickList"> <ul *ngFor="let channel of currentPickSelection"> ...

jQuery event triggers upon completion of execution

A custom code has been integrated into my project using jQuery. Check out the code snippet below: <script> $("#startProgressTimer").click(function() { $("#progressTimer").progressTimer({ timeLimit: $("#restTime").val(), onFinish ...