Learning
Learning

Reputation: 20001

Remove Space between nested tables

I am working on responsive newsletter using HTML, inline css as much as possible and some css also.

I am facing issue in design as i am not able to remove space between first Image and second table after image..

https://codepen.io/KGuide/full/oNXwyEW

 html,
        body {
            margin: 0 auto !important;
            padding: 0 !important;
            height: 100% !important;
            width: 100% !important;
            background: #fff;
        }
        
        /* What it does: Stops email clients resizing small text. */
        * {
            -ms-text-size-adjust: 100%;
            -webkit-text-size-adjust: 100%;
        }
        table,
        td {
            mso-table-lspace: 0pt !important;
            mso-table-rspace: 0pt !important;
        }
        
        /* What it does: Fixes webkit padding issue. */
        table {
            border-spacing: 0 !important;
            border-collapse: collapse !important;
            table-layout: fixed !important;
            margin: 0 auto !important;
        }
        
        /* What it does: Uses a better rendering method when resizing images in IE. */
        img {
           /* -ms-interpolation-mode:bicubic; */
        	
        }
        a {
            text-decoration: none;
        }
          .primary{
        	background: #f5564e;
        }
        .bg_white{
        	background: #ffffff;
        }
        .bg_light{
        	background: #fafafa;
        }
        .bg_black{
        	background: #000000;
        }
        .bg_dark{
        	background: rgba(0,0,0,.8);
        }
        .email-section{
        	padding:2.5em;
        }
        
        /*BUTTON*/
        .btn{
        	padding: 5px 15px;
        	display: inline-block;
        }
        .btn.btn-primary{
        	border-radius: 5px;
        	background: #f5564e;
        	color: #ffffff;
        }
        .btn.btn-white{
        	border-radius: 5px;
        	background: #ffffff;
        	color: #000000;
        }
        .btn.btn-white-outline{
        	border-radius: 5px;
        	background: transparent;
        	border: 1px solid #fff;
        	color: #fff;
        }
        
        h1,h2,h3,h4,h5,h6{
        	font-family: 'Nunito Sans', sans-serif;
        	color: #000000;
        	margin-top: 0;
        }
        
        body{
        	font-family: 'Nunito Sans', sans-serif;
        	font-weight: 400;
        	font-size: 15px;
        	line-height: 1.8;
        	color: rgba(0,0,0,.4);
        }
        
        a{
        	color: #f5564e;
        }
        
        table{
        }
        /*LOGO*/
        
        .logo h1{
        	margin: 0;
        }
        .logo h1 a{
        	color: #000;
        	font-size: 20px;
        	font-weight: 700;
        	text-transform: uppercase;
        	font-family: 'Nunito Sans', sans-serif;
        }
        
        .navigation{
        	padding: 0;
        }
        .navigation li{
        	list-style: none;
        	display: inline-block;;
        	margin-left: 5px;
        	font-size: 12px;
        	font-weight: 700;
        	text-transform: uppercase;
        }
        .navigation li a{
        	color: rgba(0,0,0,.6);
        }
        
        /*HERO*/
        .hero{
        	position: relative;
        	z-index: 0;
        }
        .hero .overlay{
        	position: absolute;
        	top: 0;
        	left: 0;
        	right: 0;
        	bottom: 0;
        	content: '';
        	width: 100%;
        	background: #000000;
        	z-index: -1;
        	opacity: .3;
        }
        .hero .icon{
        }
        .hero .icon a{
        	display: block;
        	width: 60px;
        	margin: 0 auto;
        }
        .hero .text{
        	color: rgba(255,255,255,.8);
        	padding: 0 4em;
        }
        .hero .text h2{
        	color: #ffffff;
        	font-size: 40px;
        	margin-bottom: 0;
        	line-height: 1.2;
        	font-weight: 900;
        }
        
        
        /*HEADING SECTION*/
        .heading-section{
        }
        .heading-section h2{
        	color: #000000;
        	font-size: 24px;
        	margin-top: 0;
        	line-height: 1.4;
        	font-weight: 700;
        }
        .heading-section .subheading{
        	margin-bottom: 20px !important;
        	display: inline-block;
        	font-size: 13px;
        	text-transform: uppercase;
        	letter-spacing: 2px;
        	color: rgba(0,0,0,.4);
        	position: relative;
        }
        .heading-section .subheading::after{
        	position: absolute;
        	left: 0;
        	right: 0;
        	bottom: -10px;
        	content: '';
        	width: 100%;
        	height: 2px;
        	background: #f5564e;
        	margin: 0 auto;
        }
        
        .heading-section-white{
        	color: rgba(255,255,255,.8);
        }
        .heading-section-white h2{
        	font-family: 
        	line-height: 1;
        	padding-bottom: 0;
        }
        .heading-section-white h2{
        	color: #ffffff;
        }
        .heading-section-white .subheading{
        	margin-bottom: 0;
        	display: inline-block;
        	font-size: 13px;
        	text-transform: uppercase;
        	letter-spacing: 2px;
        	color: rgba(255,255,255,.4);
        }
        
        
        .icon{
        	text-align: center;
        }
        .icon img{
        }
        
<!DOCTYPE html>
        <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
        <head>
            <meta charset="utf-8"> <!-- utf-8 works for most cases -->
            <meta name="viewport" content="width=device-width"> <!-- Forcing initial-scale shouldn't be necessary -->
            <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Use the latest (edge) version of IE rendering engine -->
            <meta name="x-apple-disable-message-reformatting">  <!-- Disable auto-scale in iOS 10 Mail entirely -->
            <title></title> <!-- The title tag shows in email notifications, like Android 4.4. -->
        
            <link href="https://fonts.googleapis.com/css?family=Nunito+Sans:200,300,400,600,700,800,900" rel="stylesheet">
        
            <title></title> <!-- The title tag shows in email notifications, like Android 4.4. -->
        
        </head>
        <style>
               
        
        </style>
        
        <body>
        
        <table style="width:100%; text-align:center;">
            <tr>
                <td style="width:100%; text-align:center; border-spacing: 0px;" >
                	<table align="center" style="width:100%; max-width:600px;">
                        <tr>
                            <td ><img src="https://dummyimage.com/600x400/cf30cf/fff.jpg" alt="" style="width:100%; max-width: 600px;"></td>
                        </tr>
                        <tr>
                            <td class=""> 
                            	<table style="width:100%; background:#525252; max-width:600px;" border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td>1</td>
                                    <td>2</td>
                                    <td>3</td>
                                  </tr>
                                  <tr>
                                    <td>1</td>
                                    <td>2</td>
                                    <td>3</td>
                                  </tr>
                                </table>
        
                            </td>
                        </tr>
                        <tr>
                            <td align="center" style="padding:15px; background:#0A0A0A;"> Move-in now to your dream home in City Center Plaza
     </td>
                        </tr>
                        <tr>
                            <td align="center" style="padding:15px; background:#0A0A0A;"> BUTTON </td>
                        </tr>
                        <tr>
                            <td style="padding:15px; background:#0A0A0A;">TEXT TEXT TEXT TEXT TEXT</td>
                        </tr>
                         <tr>
                            <td><img src="https://dummyimage.com/600x400/cf30cf/fff.jpg" alt="" style="width:100%; max-width: 600px;"> </td>
                        </tr>
                         <tr>
                           <td valign="top" align="center" style="padding:15px;">
        								
        
        								
        
                                        </td>
                        </tr>
                    </table>
                    
                </td>
            </tr>
        </table>
        
        </body>
        </html>

Upvotes: 2

Views: 1408

Answers (3)

toh19
toh19

Reputation: 1229

Replace your code with this and see if this works:

<table align="center" border="0" cellpadding="0" cellspacing="0" style="width:100%; max-width:600px; border-collapse: collapse;">
  <tr>
    <td>
      <img src="https://dummyimage.com/600x400/cf30cf/fff.jpg" alt="" style="margin: 0; border: 0; padding: 0; display: block; width:100%; max-width: 600px;">
      </td>
  </tr>

Edit:

Here is 2 tutorials they helped me while creating HTML emails:

Build an HTML Email Template From Scratch

How to Code a Responsive Email from Scratch

Upvotes: 6

dwjohnston
dwjohnston

Reputation: 11813

As pointed out by the other user, some of that space is coming from the the font size.

What I recommend is using either:

line-height: 0; 

or

font-size: 0; 

To remove that, and then put all text inside spans to put the size back up.

You also need to remove the padding from your cells,

tr, td {
    padding: 0; 
}

Complete changes required:

  tr, td {
    padding: 0; 
    line-height: 0; 
  }

  span {
    line-height: 1; 
  }

Plus wrap all text in spans.

Upvotes: 2

kp86284
kp86284

Reputation: 167

use "font-size: 0;"

and I think solve your problem

Example:-

<td style="font-size: 0;"><img src="https://dummyimage.com/600x400/cf30cf/fff.jpg" alt="" style="width:100%; max-width: 600px;"></td>

Upvotes: 0

Related Questions