居中标题标签问题

时间:2014-10-24 01:52:20

标签: html css

我确定之前已经问过这个问题,但是这里有......

我正在尝试将h3标记置于我的页面上。我只想使用内联样式来实现这一目标。

现在我已经阅读了最简单的自动中心方法:

margin-left:auto; 
margin-right:auto;

问题是不适合我。它仍然排在左侧。 我确定我可以猜到边距 - 左边的像素数量接近但是....

为什么不以它为中心?

我的实际代码:

<h3 style="margin-left:auto; margin-right:auto;">To make a donation now. Click the button
below!!</h3>

1 个答案:

答案 0 :(得分:0)

你需要定义一个宽度,以便在一个块时以边距为中心。

<h3 style="margin-left:auto; margin-right:auto; width: 300px;">To make a donation now. Click the button
below!!</h3>

如果您只想将文本居中于块中,则可以使用text-align: center

<h3 style="text-align: center;">To make a donation now. Click the button
below!!</h3>