时间:2021-07-01 10:21:17 帮助过:100人阅读

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>效果图:

以上就是css text-align属性怎么用的详细内容,更多请关注Gxlcms其它相关文章!