css - 如何将 td 内的内容水平放置在单元格中心?

标签 css jquery-mobile

在标签内我可以有文本或图标,我用类似

的模板创建了它
<td>
 <span style="margin-left: auto; margin-right: auto;">{{r['username']}}</span>
</td>
<td>
 <span style="margin-left: auto; margin-right: auto;">{% if r['nation'] == 1 %}
  <img src="../static/images/Flag_Native.png" />{% elif r['nation'] == 2 %}
  <img src="../static/images/Flag_American.png" />{% elif r['nation'] == 3 %}
  <img src="../static/images/Flag_Britain.png" />{% else %}
  <img src="../static/images/Flag_France.png"/>{% end %}
 </span>
</td>
<td>
 <span style="margin-left: auto; margin-right: auto;">{{r['score']}}
 </span>
</td>

我也尝试过只在 td 内不使用 span,例如 <td align="center">但它没有用。

如何将 td 中的内容水平放置在单元格中心?

最佳答案

尝试

<td style='margin: 0 auto; align:center;'>

或者将它包装在一个div中

<td><div style='margin: 0 auto; align:center; width: 100%;'><span style="margin-left: auto; margin-right: auto;">{{r['username']}}</span></div></td>

div 可能是最好的,因为我认为还需要设置 width 属性。

关于css - 如何将 td 内的内容水平放置在单元格中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16966762/

相关文章:

html - 兄弟元素之间的边距不会折叠

javascript - bxslider:在 div 之外显示一半图像

jquery - 简单的 jQuery 动画

jquery mobile data-theme 属性不能到处使用

jquery - 加快 iPhone 上 jQuery Mobile 的对话框/页面转换速度?

css - 如何使用 if else block 来决定 Razor 中的样式?

html - 中心列在 IE 8,9 中不起作用

javascript - 元素不会显示 js 切换功能

Jquery-Mobile:如何将示例应用程序部署到设备中

css - jquery 移动 CSS