如何在移动视图中居中对齐 td cell 或 table?
how to center align td cell or table in mobile view?
.button-center {
max-width: 100% !important;
min-width: 100px !important;
width: 100% !important;
text-align: center !important;
display: inline-block !important;
margin:auto;
}
<table cellpadding="0" cellspacing="0" role="presentation" width="100%" align="center" dir="ltr" valign="top" style="max-width:100%;">
<tbody>
<tr>
<td style="text-align: left; font-family: arial; font-size: 12px; color: #000;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</td>
</tr>
<tr>
<td style="height:24px;" height="24"></td>
</tr>
<tr>
<td style="text-align:center;">
<table cellpadding="0" class="button-center" cellspacing="0" role="presentation" style="background-color:#9E2776;max-width:100%;" align="left">
<tbody>
<tr>
<td>
<a href="" style="color:ffffff;padding:10 10;font-family: Arial;font-size: 14px;text-align: center;text-decoration: none;display: block;border-collapse: collapse;font-weight: bold;">Lorem Ipsum</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
您正在为该单元格 (.button-center
) 定义 display: inline-block
,这违背了自动 table 格式化的整个原则。只需删除它,cell/table 的内容就会居中:
.button-center {
max-width: 100% !important;
min-width: 100px !important;
width: 100% !important;
text-align: center !important;
margin: auto;
}
<table cellpadding="0" cellspacing="0" role="presentation" width="100%" align="center" dir="ltr" valign="top" style="max-width:100%;">
<tbody>
<tr>
<td style="text-align: left; font-family: arial; font-size: 12px; color: #000;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</td>
</tr>
<tr>
<td style="height:24px;" height="24"></td>
</tr>
<tr>
<td style="text-align:center;">
<table cellpadding="0" class="button-center" cellspacing="0" role="presentation" style="background-color:#9E2776;max-width:100%;" align="left">
<tbody>
<tr>
<td>
<a href="" style="color:ffffff;padding:10 10;font-family: Arial;font-size: 14px;text-align: center;text-decoration: none;display: block;border-collapse: collapse;font-weight: bold;">Lorem Ipsum</a>
</td>
</tr>
</tbody>
</table>
.button-center {
max-width: 100% !important;
min-width: 100px !important;
width: 100% !important;
text-align: center !important;
display: inline-block !important;
margin:auto;
}
<table cellpadding="0" cellspacing="0" role="presentation" width="100%" align="center" dir="ltr" valign="top" style="max-width:100%;">
<tbody>
<tr>
<td style="text-align: left; font-family: arial; font-size: 12px; color: #000;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</td>
</tr>
<tr>
<td style="height:24px;" height="24"></td>
</tr>
<tr>
<td style="text-align:center;">
<table cellpadding="0" class="button-center" cellspacing="0" role="presentation" style="background-color:#9E2776;max-width:100%;" align="left">
<tbody>
<tr>
<td>
<a href="" style="color:ffffff;padding:10 10;font-family: Arial;font-size: 14px;text-align: center;text-decoration: none;display: block;border-collapse: collapse;font-weight: bold;">Lorem Ipsum</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
您正在为该单元格 (.button-center
) 定义 display: inline-block
,这违背了自动 table 格式化的整个原则。只需删除它,cell/table 的内容就会居中:
.button-center {
max-width: 100% !important;
min-width: 100px !important;
width: 100% !important;
text-align: center !important;
margin: auto;
}
<table cellpadding="0" cellspacing="0" role="presentation" width="100%" align="center" dir="ltr" valign="top" style="max-width:100%;">
<tbody>
<tr>
<td style="text-align: left; font-family: arial; font-size: 12px; color: #000;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</td>
</tr>
<tr>
<td style="height:24px;" height="24"></td>
</tr>
<tr>
<td style="text-align:center;">
<table cellpadding="0" class="button-center" cellspacing="0" role="presentation" style="background-color:#9E2776;max-width:100%;" align="left">
<tbody>
<tr>
<td>
<a href="" style="color:ffffff;padding:10 10;font-family: Arial;font-size: 14px;text-align: center;text-decoration: none;display: block;border-collapse: collapse;font-weight: bold;">Lorem Ipsum</a>
</td>
</tr>
</tbody>
</table>