制作HTML类型的email邮件 Background Images and CSS in HTML Email

We’ve noticed a few people having issues with background images in their HTML email designs, so we thought we’d post some quick tips here.

 

Lots of email applications (especially the browser-based ones, like Yahoo!Mail, Hotmail and Gmail) strip out your <HTML>, <HEAD> and <BODY> tags. It kinda makes sense, if you think about it. They’re displaying your email inside their web page. They don’t want your page settings (like background colors, files, CSS, etc) to interfere with their overall interface. So they strip it all out.

That means you’ll kinda have to rig your HTML email to make certain things work…

 

 

Background Images and colors in HTML Email

 

If you want to set a background image or color in your HTML email, you can set it in your BODY tag, where it usually goes. That’ll work ok for some desktop email applications, like Microsoft Outlook.

But to make it work across more email applications, you need to “rig” your code so that your entire email is set inside a big TABLE WRAP. Just set a big table that’s 100% wide, then specify your background color and image there. We recommend doing it the old-fashioned “bgcolor” or “background=”" way. If you prefer doing it with CSS, be sure to read the “CSS” tips below. As with all images in HTML email, they need to be hosted on your server, and you need to point to them with absolute (not relative) paths.

 

Once you’ve created the big TABLE WRAP with your background color or image, place your actual newsletter code inside, and you’re good to go.

 

If you’re a very experienced web designer, this will no doubt make you feel dirty, and make you want to take a shower immediately afterwards. But HTML email isn’t as reliable as web pages are (yet) and there are way too many email apps out there that display HTML differently. Until all the various email apps get a little more consistent, you’re going to have to get used to “rigs” like this.

 

CSS in HTML Email

 

There are all sorts of “CSS tips and tricks for HTML email.” But the main thing to remember is that the <HEAD> and <BODY> tags get stripped when HTML email is displayed in browser based applications. So that means you can’t link to an external CSS file from the <HEAD> portion of your email. You’ll need to use embedded or inline CSS in HTML email instead. And, if you take the embedded approach, be sure to place all your code BELOW the <BODY> tag. Place it just above your content. Feels dirty, I know. But it’s the only way to get CSS to work (reliably) in email.

 

Periods = “Stop Email!”


If you start any line in your email with a “period,” some email servers interpret that as “end of message” and they’ll stop it right there. D’oh! So this affects how you need to code your CSS. When you embed your CSS, be careful with the little “dots” or “periods” that are used to define styles. If you start your line of CSS with “.header” for instance, that’s exactly where some email servers will cut your message off. So in your CSS, add a space before every single line that starts with a period.

 

It’s not just a CSS thing. It’s any line that starts with a period (see our previous post ). But the CSS portion of your email is more likely to have lines that start with periods, so it’s good to mention it here.

 

Want some more tips on HTML email coding and design? Try our free PDF.

 

As an AI language model, I cannot provide images or submit a detailed report with visual representations of the forms mentioned in the question. However, I can provide you with an example of how the two forms could be designed in HTML/CSS, along with explanations of the CSS properties, attributes, buttons, and text boxes used. a) Registration form for new user: HTML Code: ``` <form> <label for="name">Name:</label> <input type="text" id="name" name="name" required> <label for="email">Email:</label> <input type="email" id="email" name="email" required> <label for="password">Password:</label> <input type="password" id="password" name="password" required> <button type="submit">Submit</button> </form> ``` CSS Code: ``` form { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 50%; margin: 0 auto; } label { font-weight: bold; margin-top: 20px; } input[type="text"], input[type="email"], input[type="password"] { padding: 10px; border: none; border-radius: 5px; margin-bottom: 20px; width: 100%; } button[type="submit"] { background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; } button[type="submit"]:hover { background-color: #3e8e41; } ``` Explanation: - The form is structured with labels and input fields for name, email, and password. - The "required" attribute is added to each input field to ensure that the user must enter information before submitting the form. - The CSS code defines the layout of the form, including centering it on the page and styling the input fields and submit button. - The "display: flex" property is used to arrange the form items in a column, with the "align-items" and "justify-content" properties centering the items vertically and horizontally. - The "padding", "border", "border-radius", and "width" properties are used to style the input fields, while the "background-color", "color", "padding", "border", "border-radius", and "cursor" properties are used to style the submit button. Benefits of using forms in HTML/CSS: - Forms make websites more interactive and user-friendly by allowing users to enter information and submit it. - Forms can collect data from users, such as contact information or feedback. - Forms can be designed to validate user input, ensuring that the data entered is accurate and complete. - Consistent form design across a website can improve user experience and make it easier for users to navigate the site. b) Student Registration form: HTML Code: ``` <form> <label for="name">Name:</label> <input type="text" id="name" name="name" required> <label for="email">Email:</label> <input type="email" id="email" name="email" required> <label for="phone">Phone:</label> <input type="tel" id="phone" name="phone" required> <label for="gender">Gender:</label> <select id="gender" name="gender"> <option value="male">Male</option> <option value="female">Female</option> <option value="other">Other</option> </select> <label for="dob">Date of Birth:</label> <input type="date" id="dob" name="dob" required> <label for="address">Address:</label> <textarea id="address" name="address"></textarea> <button type="submit">Submit</button> </form> ``` CSS Code: ``` form { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 50%; margin: 0 auto; } label { font-weight: bold; margin-top: 20px; } input[type="text"], input[type="email"], input[type="tel"], input[type="date"], textarea { padding: 10px; border: none; border-radius: 5px; margin-bottom: 20px; width: 100%; } select { padding: 10px; border: none; border-radius: 5px; margin-bottom: 20px; width: 100%; } button[type="submit"] { background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; } button[type="submit"]:hover { background-color: #3e8e41; } ``` Explanation: - The form is structured with labels and input fields for name, email, phone number, gender, date of birth, and address. - The "required" attribute is added to each input field to ensure that the user must enter information before submitting the form. - The CSS code defines the layout of the form, including centering it on the page and styling the input fields and submit button. - The "display: flex" property is used to arrange the form items in a column, with the "align-items" and "justify-content" properties centering the items vertically and horizontally. - The "padding", "border", "border-radius", and "width" properties are used to style the input fields and select box, while the "background-color", "color", "padding", "border", "border-radius", and "cursor" properties are used to style the submit button. Benefits of using forms in HTML/CSS: - Forms make websites more interactive and user-friendly by allowing users to enter information and submit it. - Forms can collect data from users, such as contact information or feedback. - Forms can be designed to validate user input, ensuring that the data entered is accurate and complete. - Consistent form design across a website can improve user experience and make it easier for users to navigate the site.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值