【问题标题】:how to center align td cell or table in mobile view?如何在移动视图中居中对齐 td 单元格或表格?
【发布时间】:2020-10-16 12:54:56
【问题描述】:

.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>

【问题讨论】:

    标签: html css mobile html-table responsive


    【解决方案1】:

    您正在为该单元格 (.button-center) 定义 display: inline-block,这违背了自动表格格式化的整个原则。只需删除它,该单元格/表格的内容就会居中:

    .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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-28
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-02
      • 2013-07-14
      相关资源
      最近更新 更多