dd

CSS text-align 属性


实例

h1, h2, 和 h3元素设置文本的对齐方式:

h1 {text-align:center}
h2 {text-align:left}
h3 {text-align:right}
运行一下 »

在此页底部有更多的例子。

属性定义及使用说明

text-align属性指定元素文本的水平对齐方式。

默认值:left if direction is ltr, and right if direction is rtl
继承:yes
版本:CSS1
JavaScript 语法:object.style.textAlign="right"

浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主流浏览器都支持text-align属性。

注意:IE7和更早的版本不支持"inherit"的值。IE8需要定义!DOCTYPE。IE9支持"inherit"。

属性值

描述
left把文本排列到左边。默认值:由浏览器决定。
right把文本排列到右边。
center把文本排列到中间。
justify实现两端对齐文本效果。
inherit规定应该从父元素继承 text-align 属性的值。

在线实例

更多高级文本对齐的例子
这个例子演示了一个更高级的文本对齐的例子。