html - 如何在移动视图中居中对齐 td 单元格或表格?
问题描述
.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>
解决方案
您正在display: inline-block
为该单元格 ( .button-center
) 进行定义,这违反了自动表格格式化的整个原则。只需删除它,该单元格/表格的内容就会居中:
.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>
推荐阅读
- python - 发送以当前日期为主题的邮件
- android - 在某些设备中应用“fitsSystemWindows”后创建了一个空间。我怎样才能删除它?
- python - 模型预测 JSON 请求格式在 python 请求中不起作用:Google AI 平台
- python - 运行 Python + Behave 自动化项目并尝试在其他步骤中执行步骤
- google-cloud-platform - 原因:com.google.api.client.googleapis.json.GoogleJsonResponseException: 412 Precondition Failed while remove bucket IAM Member
- ios - 如何使用 get 方法显示 Json 响应
- javascript - 如何限制用户在日期字段中手动输入日期
- reactjs - 单击处理程序未在 Firefox 中的 foreignObject 外部触发
- node.js - 如何将 NodeJS 应用程序转换为 war 文件
- c# - 如何将我的 HoloLens 应用程序的点击手势转换为我的桌面应用程序的鼠标单击?