【问题标题】:text-align = center not working文本对齐 = 中心不工作
【发布时间】:2019-01-02 19:09:13
【问题描述】:

我正在练习 html 电子邮件并尝试将文本居中。但它不工作。我也怀疑这不起作用,因为我在字体标签内使用样式标签。我已经在 validator.w3.org 中测试了我的代码并且它通过了。这段代码有什么问题吗。请帮我将文本居中对齐。

Doctype is : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<tr>
  <td>
    <font style="font-family: verdana; font-size:10px; font-weight: bold; text-align: right;"><i>
"We are such stuff as dream are made on, and our little life is rounded with a sleep"  William Shakespeare</i>
		</font>
  </td>
</tr>

【问题讨论】:

标签: fonts html-table html-email


【解决方案1】:

这是您更正后的代码:

<table width="100%">
<tr>
  <td style="text-align: right;"> 
    <font style="font-family: verdana; font-size:10px; font-weight: bold;"><i>
"We are such stuff as dream are made on, and our little life is rounded with a sleep"  William Shakespeare</i>
		</font>
  </td>
</tr>
</table>

【讨论】:

  • 对不起,我已经通过使文本右对齐来测试代码,看看它是否有效。我忘记在发布之前将其更改回中心。
  • 谢谢加布里埃尔。所以当我插入 时 text-align 现在可以工作了。就像您在代码中提到的那样。你知道为什么我们把 font , style 标签放在里面时它不起作用吗?
  • "CSS 中的 text-align 属性用于对齐 block 元素的内部内容。" (css-tricks.com/almanac/properties/t/text-align) 是一个内联元素,因此不应该使用 text-align 属性。
  • 如果解决了您的问题,请标记为已回答。谢谢! :-)
【解决方案2】:

使用 align="left" 属性而不是 text-align

【讨论】:

  • HTML5 不支持
猜你喜欢
相关资源
最近更新 更多
热门标签