Lo sviluppo di email HTML richiede layout difensivi basati su tabelle per garantire una resa corretta su client desktop e mobile.
Peculiarità dei Client e CSS da Evitare
Proprietà da Evitare
| Proprietà e Ambito | Client Problematici | Alternativa Sicura |
|---|---|---|
width su p o div |
Microsoft Outlook | Specificare width sugli elementi td |
padding su p o div |
Microsoft Outlook | Applicare padding sulle celle td |
margin (in qualsiasi forma) |
Outlook, Hotmail | Usare celle di spaziatura nella tabella |
background-image |
Outlook Windows desktop | Utilizzare tag Microsoft VML |
Immagini data-uri |
Webmail clients | Ospitare le immagini su CDN HTTPS esterno |
Selettori da Evitare
| Tipo di Selettore | Client Problematici |
|---|---|
| Pseudo-elementi (::before, ::after) | Outlook, Yahoo, Gmail |
| Selettori adiacenti e discendenti diretti (E + F, E > F) | Outlook, Gmail App |
| Selettori di attributo ([href^="https"]) | Vecchi client webmail |
Regola fondamentale: definire sempre tutto il CSS inline negli attributi style="..." sulle celle td.
Struttura Base per Email Responsive
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Responsive Email</title>
<style type="text/css">
@media only screen and (max-width: 600px) {
.container { width: 100% !important; }
}
</style>
</head>
<body style="margin: 0; padding: 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center" style="padding: 20px 0;">
<table class="container" border="0" cellpadding="0" cellspacing="0" width="600" style="border-collapse: collapse;">
<tr>
<td style="color: #333333; font-family: Arial, sans-serif; font-size: 16px; line-height: 24px;">
Il contenuto dell'email va inserito qui.
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>