语法格式:
text-align:(文本位置)
位置 说明
left 左对齐
right 右对齐
center 居中对齐
justify 两端对齐
接下我们来分别看看这四种对齐方式的设置方法
文本左对齐的设置方法:
text-align:left;
文本右对齐设置方法:
text-align:right;
文本居中对齐设置方法:
text-align:center;
文本两端对齐设置方法:
text-align:justify;
我们来看具体的代码示例1:
TextAlign.html
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf-8"/>
<linkrel="stylesheet"href="TextAlign.css"/>
<title></title>
</head>
<body>
<divclass="TextLeft">
php中文网左对齐<br/>
php中文网<br/>
php中文网<br/>
php
</div>
<divclass="TextRight">
php中文网右对齐<br/>
php中文网<br/>
php中文网<br/>
php
</div>
<divclass="TextCenter">
php中文网居中对齐<br/>
php中文网<br/>
php中文网<br/>
php
</div>
<divclass="TextJustify">
php中文网<br/>
两端对齐<br/>
php中文网<br/>
php
</div>
</body>
</html>
TextAlign.css
.TextLeft{
margin-top:24px;
margin-left:32px;
border:1pxsolid#ff6a00;
width:480px;
text-align:left;
}
.TextRight{
margin-top:24px;
margin-left:32px;
border:1pxsolid#ff6a00;
width:480px;
text-align:right;
}
.TextCenter{
margin-top:24px;
margin-left:32px;
border:1pxsolid#ff6a00;
width:480px;
text-align:center;
}
.TextJustify{
margin-top:24px;
margin-left:32px;
border:1pxsolid#ff6a00;
width:480px;
text-align:justify;
text-justify:distribute-all-lines;
}
显示结果
使用Web浏览器显示上述HTML文件。将显示如下所示的效果。
360截图20181115101423160.jpg
代码示例2:
文本左对齐:
<!DOCTYPEhtml>
<html>
<head>
<title></title>
<metacharset="utf-8">
<styletype="text/css">
.leftText{
text-align:left;
}
</style>
</head>
<body>
<divclass="leftText">左对齐</div>
</body>
</html>
文本右对齐:
<!DOCTYPEhtml>
<html>
<head>
<title></title>
<metacharset="utf-8">
<styletype="text/css">
.rightText{
text-align:right;
}
</style>
</head>
<body>
<divclass="rightText">右对齐</div>
</body>
</html>
居中对齐:
<!DOCTYPEhtml>
<html>
<head>
<title></title>
<metacharset="utf-8">
<styletype="text/css">
.centerText{
text-align:center;
}
</style>
</head>
<body>
<divclass="centerText">居中对齐</div>
</body>
</html>


本文转载自中文网


本文转载自中文网
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/css3-style/c54919.shtml