css text-align属性怎么用

2020-07-23 07:44:01
css text-align属性用于设置元素中文本的水平对齐方式。该属性通过指定行框与哪个点对齐,从而设置块级元素内文本的水平对齐方式。通过允许用户代理调整行内容中字母和字之间的间隔,可以支持值 justify;不同用户代理可能会得到不同的结果。

css text-align属性怎么用?

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

语法:

text-align : left | right | center | justify | inherit;

属性值:

● left:把文本排列到左边。默认值:由浏览器决定。

● right:把文本排列到右边。

● center:把文本排列到中间。

● justify:实现两端对齐文本效果。

● inherit:规定应该从父元素继承 text-align 属性的值。

说明:该属性通过指定行框与哪个点对齐,从而设置块级元素内文本的水平对齐方式。通过允许用户代理调整行内容中字母和字之间的间隔,可以支持值 justify;不同用户代理可能会得到不同的结果。

注释:所有浏览器都支持 text-align 属性。任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 "inherit"。

css text-align属性 示例

<!DOCTYPE html><html><head><meta charset="utf-8"><style type="text/css">.box{width: 400px;height: 200px;border: 1px solid red;}h1 {text-align: center}h2 {text-align: left}h3 {text-align: right}</style></head><body><div class="box"><h1>这是标题 1</h1><h2>这是标题 2</h2><h3>这是标题 3</h3></div></body></html>

效果图:

1.jpg