Css 在电子邮件的HTML中使用中心对齐
我开始使用表格为电子邮件编写html。现在,我第一次尝试使用Css 在电子邮件的HTML中使用中心对齐,css,html,alignment,center,Css,Html,Alignment,Center,我开始使用表格为电子邮件编写html。现在,我第一次尝试使用divs编写代码,但这导致了一个问题:我无法将以前能够居中的所有内容居中对齐 也许我写的不正确,但这是我发现的唯一方法,在写完之后能够复制从浏览器到Gmail的所有内容 有人能告诉我如何在这个代码中居中对齐吗 如果有人能告诉我是否有更好的方法来编写这段代码,我会很高兴收到批评和有用的信息 附言:我尝试了填充、定位、边距、放置高度和宽度,但在大多数结果中,这些选项使我的背景或背景的一半完全消失了 <!DOCTYPE html PUB
div
s编写代码,但这导致了一个问题:我无法将以前能够居中的所有内容居中对齐
也许我写的不正确,但这是我发现的唯一方法,在写完之后能够复制从浏览器到Gmail的所有内容
有人能告诉我如何在这个代码中居中对齐吗
如果有人能告诉我是否有更好的方法来编写这段代码,我会很高兴收到批评和有用的信息
附言:我尝试了填充、定位、边距、放置高度和宽度,但在大多数结果中,这些选项使我的背景或背景的一半完全消失了
<!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" />
<title>Untitled Document</title>
<style type="text/css">
div#Container {
width: 895px;
height: 525px;
position: absolute;
left: 9px;
top: 15px;
}
div#Room {
padding-left: 245px;
padding-top: 80px;
width: 625px;
}
#Room span {
font-family: Times New Roman, Times, serif;
font-weight: bold;
font-size: 23px;
color: #522405;
}
#D { padding-left: 70px;
}
#GD { padding-left: 103px;
}
#GPV { padding-left: 53px;
}
div#Content {
padding-left: 245px;
padding-top: 10px;
width: 625px;
}
#Right {
position: absolute;
left: 872px;
top: 222px;
}
img.Spacer {
margin-left: 10px;
}
div.content {
font-family: Arial, Helvetica, sans-serif;
color: black;
font-size: 17px;
font-weight: bold;
}
.BP {
vertical-align: text-top;
margin-top: 10px;
margin-left: 245px;
}
.table {
vertical-align: text-top;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
text-align: center;
color: #002b55;
margin-left:245px;
}
.TD {
margin-left: 30px;
}
.adress {
font-family: Times New Roman, Times, serif;
font-size: 10px;
text-align: center;
font-weight: bold;
color: #100073;
}
.OOT {
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: bold;
color: #100073;
text-align:center;
}
.res {
vertical-align: top;
padding-left: 25px;
}
</style>
</head>
<body>
<div>
<img style="position: relative;" src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/BK_zpsa93ab347.png" alt="Background" />
</div>
<div id="Container">
<div id="Room" >
<a href="http://bit.ly/XSyPG5" title="Deluxe" target="_blank" >
<img src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/D_zpsf4ea5de8.jpg" border="0px" alt="Deluxe" />
</a>
<a href="http://bit.ly/XSyPG5" title="Grand Deluxe" target="_blank" >
<img class="Spacer" src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/GD_zpse78278b7.jpg" border="0px" alt="Grand Deluxe" />
</a>
<a href="http://bit.ly/XSyPG5" title="Grand Pool Villa" target="_blank" >
<img class="Spacer" src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/GPV_zpsb381cd33.jpg" border="0px" alt="Grand Pool Villa" />
</a>
<br />
<a href="http://bit.ly/XSyPG5" title="Deluxe" target="_blank" style="text-decoration: none;"><span id="D">Deluxe</span></a>
<a href="http://bit.ly/XSyPG5" title="Grand Deluxe" target="_blank" style="text-decoration: none;"><span id="GD">Grand Deluxe</span></a>
<a href="http://bit.ly/XSyPG5" title="Grand Pool Villa" target="_blank" style="text-decoration: none;"><span id="GPV">Grand Pool Villa</span></a>
</div>
<div id="Content" class="content">Situated on a hill, Ayara Kamala offers a beautiful garden and ocean view rooms. The place of the hotel provides quiet, calm and romantic holiday away from all other hotels on Kamala Beach.
<br />
<br />
Big size of rooms, king size beds and impressive bathrooms, are making Ayara Kamala perfect selection for couples who are looking for privacy and relaxing holiday.
</div>
<table class="table" style="border-collapse: separate; border-spacing: 1px;" width="625" border="0">
<tr>
<td align="right" style="padding-left: 20px;" width="302"><a href="http://bit.ly/XSyPG5" title="Book Now !"><img src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/BP_zps15c948a1.png" border="0px" alt="Best Rate"/></a></td>
<td width="321" valign="top"><table class="TD" style="border-collapse: separate; border-spacing: 0px;" border="0px">
<tr>
<td height="30" class="res" align="center"><a href="http://bit.ly/XSyPG5" title="B2B Online Booking"><span>www.b2b.onlyonetour.com</span></a></td>
</tr>
<tr>
<td class="res" height="30" align="center"><span>Tel : (66) 02 - 688 - 8883 </span> </td>
</tr>
<tr>
<td class="res" height="30" align="center"><a href="mailto:rsvn@onlyonetour.com" title="E-mail Reservation"><span>rsvn@onlyonetour.com</span></a></td>
</tr></table>
</td>
</tr>
</table>
<div align="center" id="Right"><a style="text-decoration: none;" href="http://bit.ly/XSyPG5" title="Only One Tour & Travel Group Co., Ltd." target="_blank"><img width="149px" height="90px" src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/logoOOT_zps24c21653.png" border="0px" alt="Logo" /></a>
<a style="text-decoration: none;" href="http://bit.ly/XSyPG5" title="Only One Tour & Travel Group Co., Ltd." target="_blank"><span class="OOT">Only One Tour & Travel<br />Group Co., Ltd.</span></a><br /><br />
<a style="text-decoration: none;" href="http://on.fb.me/XXqq56" title="Only One Tour Facebook Page" target="_blank"> <img src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/facebook-logo-png-format-i18_zps83b6a9aa.png" width="145px" height="50px" border="0px" alt="FB"/></a><br /><br />
<span class="adress">2128/9-11 Charoenkung Rd.,</span><br />
<span class="adress">Watprayakrai, Bangkorleam,</span><br />
<span class="adress">10120 Bangkok, Thailand.</span><br />
<a class="adress" href="http://bit.ly/XSyPG5" target="_blank">www.b2b.onlyonetour.com</a><br />
<a class="adress" href="http://on.fb.me/XXqq56" target="_blank">www.onlyonetour.com (offline)</a>
</div>
</div>
</body>
</html>
无标题文件
分区#集装箱{
宽度:895px;
高度:525px;
位置:绝对位置;
左:9px;
顶部:15px;
}
休息室{
左侧填充:245px;
填充顶部:80px;
宽度:625px;
}
#房间跨度{
字体系列:泰晤士报新罗马,泰晤士报,衬线;
字体大小:粗体;
字体大小:23px;
颜色:#522405;
}
#D{左:70px;
}
#GD{左:103px;
}
#GPV{左:53px;
}
分区内容{
左侧填充:245px;
填充顶部:10px;
宽度:625px;
}
#对{
位置:绝对位置;
左:872px;
顶部:222px;
}
img.垫片{
左边距:10px;
}
部门内容{
字体系列:Arial、Helvetica、无衬线字体;
颜色:黑色;
字号:17px;
字体大小:粗体;
}
.英国石油公司{
垂直对齐:文本顶部;
边缘顶部:10px;
左边距:245px;
}
.桌子{
垂直对齐:文本顶部;
字体系列:Arial、Helvetica、无衬线字体;
字体大小:20px;
文本对齐:居中;
颜色:#002b55;
左边距:245px;
}
.TD{
左边距:30px;
}
.地址{
字体系列:泰晤士报新罗马,泰晤士报,衬线;
字体大小:10px;
文本对齐:居中;
字体大小:粗体;
颜色:#100073;
}
奥特先生{
字体系列:Arial、Helvetica、无衬线字体;
字体大小:13px;
字体大小:粗体;
颜色:#100073;
文本对齐:居中;
}
.res{
垂直对齐:顶部;
左侧填充:25px;
}
阿亚拉·卡马拉坐落在一座小山上,拥有美丽的花园和海景房。酒店所在地远离卡马拉海滩上的所有其他酒店,提供安静、平静和浪漫的假日。
大房间、特大号床和令人印象深刻的浴室,使阿亚拉·卡马拉成为寻求隐私和放松假期的夫妇的完美选择。
电话:(66)02-688-8883
查伦孔路2128/9-11号,
班科勒姆瓦特普拉亚克拉伊,
泰国曼谷10120号。
通过设置宽度:100%,为容器提供页面的整个宽度代码>,然后将要居中的div的边距设置为自动:
margin-left: auto;
margin-right: auto;
现在只为时事通讯添加
像这样
<div align="center">
<img style="position: relative;" src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/BK_zpsa93ab347.png" alt="Background" />
</div>
<div id="Container" align="center">
// your code
</div>
//你的代码
无标题文件
身体{
背景:url(http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/BK_zpsa93ab347.png)无重复顶部#FFF;
}
#包装纸
{
宽度:950px;
保证金:0px自动;
填充:0px;
}
分区#集装箱{
宽度:895px;
高度:525px;
位置:绝对位置;
左:9px;
顶部:15px;
}
休息室{
左侧填充:410像素;
填充顶部:80px;
宽度:625px;
}
#房间跨度{
字体系列:泰晤士报新罗马,泰晤士报,衬线;
字体大小:粗体;
字体大小:23px;
颜色:#522405;
}
#D{左:70px;
}
#GD{左:103px;
}
#GPV{左:53px;
}
分区内容{
左侧填充:410像素;
填充顶部:10px;
宽度:625px;
}
#对{
位置:绝对位置;
左:1030px;
顶部:222px;
}
img.垫片{
左边距:10px;
}
部门内容{
字体系列:Arial、Helvetica、无衬线字体;
颜色:黑色;
字号:17px;
字体大小:粗体;
}
.英国石油公司{
垂直对齐:文本顶部;
边缘顶部:10px;
左侧填充:410像素;
}
.桌子{
垂直对齐:文本顶部;
字体系列:Arial、Helvetica、无衬线字体;
字体大小:20px;
文本对齐:居中;
颜色:#002b55;
左侧填充:410像素;
}
.TD{
左边距:30px;
}
.地址{
字体系列:泰晤士报新罗马,泰晤士报,衬线;
字体大小:10px;
文本对齐:居中;
字体大小:粗体;
颜色:#100073;
}
奥特先生{
字体系列:Arial、Helvetica、无衬线字体;
字体大小:13px;
字体大小:粗体;
颜色:#100073;
文本对齐:居中;
}
.res{
垂直对齐:顶部;
左侧填充:25px;
}
阿亚拉·卡马拉坐落在一座小山上,拥有美丽的花园和海景房。酒店所在地远离卡马拉海滩上的所有其他酒店,提供安静、平静和浪漫的假日。
大房间、特大号床和令人印象深刻的浴室,使阿亚拉·卡马拉成为寻求隐私和放松假期的夫妇的完美选择。
电话:(66)02-688-8883
查伦孔路2128/9-11号,
班科勒姆瓦特普拉亚克拉伊,
泰国曼谷10120号。
我更改了您的代码并使其居中对齐。对于首先使用div,您已设置主id(div,命名为warapper),并将边距设置为边距:0px auto;它会自动将页面中心与所有浏览器对齐如果容器是块元素,并且很可能是块元素,那么将其宽度设置为100%
是没有意义的,除非它是从正常流中取出的。首先-为什么要使用这么多位置:绝对
?如果要将div#内容居中
请删除位置:绝对
并设置边距:自动
。如果您需要position:absolute
setleft:50%
和margin left:-447px
(容器宽度的一半)。我想您指的是我的div#Cntainer,而不是div#Content。无论如何,这是因为我希望这个div保持在我的图像div的背景上。如果你有任何其他建议,如何使它请让我知道。你写的这封信对我一点帮助都没有……不管你想把div
放在中间,你都可以通过设置widt来实现
<!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" />
<title>Untitled Document</title>
<style type="text/css">
body{
background: url(http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/BK_zpsa93ab347.png) no-repeat top#FFF;
}
#wrapper
{
width:950px;
margin:0px auto;
padding:0px;
}
div#Container {
width: 895px;
height: 525px;
position: absolute;
left: 9px;
top: 15px;
}
div#Room {
padding-left: 410px;
padding-top: 80px;
width: 625px;
}
#Room span {
font-family: Times New Roman, Times, serif;
font-weight: bold;
font-size: 23px;
color: #522405;
}
#D { padding-left: 70px;
}
#GD { padding-left: 103px;
}
#GPV { padding-left: 53px;
}
div#Content {
padding-left: 410px;
padding-top: 10px;
width: 625px;
}
#Right {
position: absolute;
left:1030px;
top: 222px;
}
img.Spacer {
margin-left: 10px;
}
div.content {
font-family: Arial, Helvetica, sans-serif;
color: black;
font-size: 17px;
font-weight: bold;
}
.BP {
vertical-align: text-top;
margin-top: 10px;
padding-left: 410px;
}
.table {
vertical-align: text-top;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
text-align: center;
color: #002b55;
padding-left: 410px;
}
.TD {
margin-left: 30px;
}
.adress {
font-family: Times New Roman, Times, serif;
font-size: 10px;
text-align: center;
font-weight: bold;
color: #100073;
}
.OOT {
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: bold;
color: #100073;
text-align:center;
}
.res {
vertical-align: top;
padding-left: 25px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="Container">
<div id="Room" >
<a href="http://bit.ly/XSyPG5" title="Deluxe" target="_blank" >
<img src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/D_zpsf4ea5de8.jpg" border="0px" alt="Deluxe" />
</a>
<a href="http://bit.ly/XSyPG5" title="Grand Deluxe" target="_blank" >
<img class="Spacer" src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/GD_zpse78278b7.jpg" border="0px" alt="Grand Deluxe" />
</a>
<a href="http://bit.ly/XSyPG5" title="Grand Pool Villa" target="_blank" >
<img class="Spacer" src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/GPV_zpsb381cd33.jpg" border="0px" alt="Grand Pool Villa" />
</a>
<br />
<a href="http://bit.ly/XSyPG5" title="Deluxe" target="_blank" style="text-decoration: none;"><span id="D">Deluxe</span></a>
<a href="http://bit.ly/XSyPG5" title="Grand Deluxe" target="_blank" style="text-decoration: none;"><span id="GD">Grand Deluxe</span></a>
<a href="http://bit.ly/XSyPG5" title="Grand Pool Villa" target="_blank" style="text-decoration: none;"><span id="GPV">Grand Pool Villa</span></a>
</div>
<div id="Content" class="content">Situated on a hill, Ayara Kamala offers a beautiful garden and ocean view rooms. The place of the hotel provides quiet, calm and romantic holiday away from all other hotels on Kamala Beach.
<br />
<br />
Big size of rooms, king size beds and impressive bathrooms, are making Ayara Kamala perfect selection for couples who are looking for privacy and relaxing holiday.
</div>
<table class="table" style="border-collapse: separate; border-spacing: 1px;" width="625" border="0">
<tr>
<td align="right" style="padding-left: 20px;" width="302"><a href="http://bit.ly/XSyPG5" title="Book Now !"><img src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/BP_zps15c948a1.png" border="0px" alt="Best Rate"/></a></td>
<td width="321" valign="top"><table class="TD" style="border-collapse: separate; border-spacing: 0px;" border="0px">
<tr>
<td height="30" class="res" align="center"><a href="http://bit.ly/XSyPG5" title="B2B Online Booking"><span>www.b2b.onlyonetour.com</span></a></td>
</tr>
<tr>
<td class="res" height="30" align="center"><span>Tel : (66) 02 - 688 - 8883 </span> </td>
</tr>
<tr>
<td class="res" height="30" align="center"><a href="mailto:rsvn@onlyonetour.com" title="E-mail Reservation"><span>rsvn@onlyonetour.com</span></a></td>
</tr></table>
</td>
</tr>
</table>
<div align="center" id="Right"><a style="text-decoration: none;" href="http://bit.ly/XSyPG5" title="Only One Tour & Travel Group Co., Ltd." target="_blank"><img width="149px" height="90px" src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/logoOOT_zps24c21653.png" border="0px" alt="Logo" /></a>
<a style="text-decoration: none;" href="http://bit.ly/XSyPG5" title="Only One Tour & Travel Group Co., Ltd." target="_blank"><span class="OOT">Only One Tour & Travel<br />Group Co., Ltd.</span></a><br /><br />
<a style="text-decoration: none;" href="http://on.fb.me/XXqq56" title="Only One Tour Facebook Page" target="_blank"> <img src="http://i1300.photobucket.com/albums/ag93/dobriyan/E-mail%20-%20Ayara%20Kamala/facebook-logo-png-format-i18_zps83b6a9aa.png" width="145px" height="50px" border="0px" alt="FB"/></a><br /><br />
<span class="adress">2128/9-11 Charoenkung Rd.,</span><br />
<span class="adress">Watprayakrai, Bangkorleam,</span><br />
<span class="adress">10120 Bangkok, Thailand.</span><br />
<a class="adress" href="http://bit.ly/XSyPG5" target="_blank">www.b2b.onlyonetour.com</a><br />
<a class="adress" href="http://on.fb.me/XXqq56" target="_blank">www.onlyonetour.com (offline)</a>
</div>
</div>
</div>
</body>
</html>