1. 排版
  2. 文本对齐

Quick reference

属性
text-lefttext-align: left;
text-centertext-align: center;
text-righttext-align: right;
text-justifytext-align: justify;
text-starttext-align: start;
text-endtext-align: end;

基本用法

¥Basic usage

设置文本对齐方式

¥Setting the text alignment

使用 text-lefttext-centertext-righttext-justify 工具来控制元素的文本对齐方式。

¥Use the text-left, text-center, text-right, and text-justify utilities to control the text alignment of an element.

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

<p class="text-left ...">So I started to walk into the water...</p>

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

<p class="text-center ...">So I started to walk into the water...</p>

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

<p class="text-right ...">So I started to walk into the water...</p>

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

<p class="text-justify ...">So I started to walk into the water...</p>

有条件地应用

悬停、聚焦和其他状态

Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:text-center 仅在 hover 时应用 text-center 工具。

<p class="text-left hover:text-center">
  <!-- ... -->
</p>

有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。

断点和媒体查询

你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:text-center 仅在中等屏幕尺寸及以上时应用 text-center 工具。

<p class="text-left md:text-center">
  <!-- ... -->
</p>

要了解更多信息,请查看有关 响应式设计暗黑模式、以及 其他媒体查询修饰符 的文档。