<!DOCTYPE html>
<html>
<head>
<title>文字對齊示例</title>
<style>
.text-left {
text-align: left;
}
.text-center {
text-align: center;
}
.text-right {
text-align: right;
}
</style>
</head>
<body>
<div class="text-left">這段文字左對齊。</div>
<div class="text-center">這段文字居中對齊。</div>
<div class="text-right">這段文字右對齊。</div>
</body>
</html>
在上面的HTML代碼中,我們首先在<style>標籤內定義了三個CSS類:text-left、text-center和text-right,分別用於設置文本的對齊方式為左對齊、居中對齊和右對齊。然後,在<body>部分,我們創建了三個<div>元素,每個元素分別應用了一種對齊方式。這樣,文本就會按照指定的方式對齊顯示。